Announcement

Collapse
No announcement yet.

newbie

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • newbie

    i got this code:

    print "<a HREF=\".$row['sciezka'].\"><img SRC=\".$row['thumb'].\"><br>.$row['nazwa'].(.$row['ile'].)</A>"

    and i get this error :

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\foxserv\www\tapety\kategoria.php on line 10

    what's wrong ?

  • #2
    i am not too good in php, but for myscript with uses array, i assign the array to a variable

    $sciezka = $row['sciezka'];
    $thumb = $row['thumb'] ;

    i am not to sure will work or not.

    Comment


    • #3
      thx... it's working

      Comment


      • #4
        or.. you can try this:
        Code:
        print "<a HREF=\".${row['sciezka']}.\"><img SRC=\".$row['thumb'].\"><br>.${row['nazwa']}.(.{$row['ile']}.)</A>"

        Comment


        • #5
          Re: newbie

          Originally posted by Domel
          i got this code:

          print "<a HREF=\".$row['sciezka'].\"><img SRC=\".$row['thumb'].\"><br>.$row['nazwa'].(.$row['ile'].)</A>"

          and i get this error :

          Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\foxserv\www\tapety\kategoria.php on line 10

          what's wrong ?
          Instead of all of that going in and out of quotes, just take the single quotes out. I am well aware of the possible complications from not using single quotes (with constants and such), but those do not apply when you are inside double quotes.


          PHP Code:
          print "<a HREF=\"$row[sciezka]\"><img SRC=\"$row[thumb]\"><br>$row[nazwa]($row[ile])</A>"
          I don't recommend this:

          $nazwa = $row['nazwa'];

          That's a newbie workaround and is not a good idea because first you are wasting time re-assigning a temporary variable, you are wasting space, and useless temp variables like that only set you up for more debugging and maintenance hassles down the road.

          Comment


          • #6
            Are you pulling that from a DB? And is that inside a loop?
            If so, you may want to think about using extract().
            PHP Code:
            while ($row=mysql_fetch_array($resultMYSQL_ASSOC)) {
                
            extract($row);
                print 
            "<a HREF=\"$sciezka\"><img SRC=\"$thumb\"><br>$nazwa($ile)</A>";

            Comment


            • #7
              Max,

              Still no reason to use extract(), that's just more unecessary temp variables...

              Comment


              • #8
                not if you do something like this:
                PHP Code:
                while (@extract(@mysql_fetch_array($resultMYSQL_ASSOC))) { 

                Comment


                • #9
                  I sometimes throw project settings into a DB. Here is what the table looks like:
                  Code:
                  +----+-----------+-------------+--------+
                  | ID | var       | val         | define |
                  +----+-----------+-------------+--------+
                  |  1 | image_dir | /images     | false  |
                  |  2 | site_name | Sporkopolis | false  |
                  |  3 | BG_COLOR  | #FFFFFF     | true   |
                  +----+-----------+-------------+--------+
                  
                  data types:
                  ID = int
                  var = varchar(255)
                  val = varchar(255)
                  define = enum('true','false')
                  And here is the code that makes my vars and constants:
                  PHP Code:
                  $query "SELECT * FROM table_name";
                  $result mysql_query($query);
                  if (!
                  $result) {
                      
                  Query_Error(__FILE____LINE__$query);
                      
                      
                  // set some default values:
                      
                  $image_dir '/images';
                      
                  $site_name 'Sporkopolis';
                      
                  define("BG_COLOR""#FFFFFF");
                      
                  }

                  while (
                  $result && @extract(@mysql_fetch_array($resultMYSQL_ASSOC))) {
                      
                      if (
                  $define=='true') {
                          
                  define($var$val);
                      }
                      else {
                          ${
                  $var} = $val;
                      }
                      

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...
                  X