Jump to content

[SOLVED] can sombody please explain to me this mysql_query line please; with parentheses?


mac007

Recommended Posts

Hello, all: I was trying to understand this long script that I have and found this line in which parentheses appear, I dont recall seeing that at all before... this script takes image-paths from an IMAGES table that are related to an ITEMS table thru each record's ID... so, pretty much what it does, it fetches the common images that belong to a specific record and shows it along with the record...  can you explain how these parentheses work here? their meaning?  it's not like they are if-else statements, are they?  Thanks!

  <CODE>

$images = mysql_query("SELECT * FROM item_image WHERE item_id = '{$item['item_id']}'");

    while($image = mysql_fetch_assoc($images)){

  echo '<img src="images/thumbs/'.$image['image_file'].'" />';

 

</CODE>

Are you talking about the {} curly braces? They are there because complex variables (ie arrays and objects) should be surrounded by curly braces when within a string.

 

Another way to write the exact same thing would have been....

 

$images = mysql_query("SELECT * FROM item_image WHERE item_id = '". $item['item_id'] ."'");

thanks Thorpe...

 

Yes, I am talking about the curly braces inside the mysql query. OK, I'm still a bit confused... I do see that this part: '{$item['item_id']}' refers to the "while" array $item, specifically the item_id field, so is that the only time I would have a need to use the brackets in there??  strange to do it that way, when the other way you mention seems just a fine.. or clearer even..

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.