Jump to content

Store data from the first retrieved row


son

Recommended Posts

I retrieve date from database via:

$query = "SELECT * FROM gallery";$result = mysqli_query ($dbc, $query);	if (mysqli_num_rows($result) > 0)	{		while ($row = mysqli_fetch_array ($result, MYSQL_ASSOC))			{		$id = $row['img_id'];		$text = $row['text'];		echo $text;		echo $id;		}	}

How can I use an array or something similar, so I can use the data from the first retrieved row further down on the page?Son

Link to comment
Share on other sites

you can use mysql_result()
Thanks for reply, but cannot use this as:- It says 'Retrieves the contents of one cell from a MySQL result set.' -> I need three cells from first row- Also I use mysqli instead of mysql, not sure if I could mix?Son
Link to comment
Share on other sites

It says 'Retrieves the contents of one cell from a MySQL result set.' -> I need three cells from first row
It's not an option to use it 3 times? There's not a function that gets 3 fields from a row.Just get the entire row and if you're looking at the first row then save the fields into variables. You can use a counter to figure out which row you're on, or better yet just set the variables if they aren't already set.
Link to comment
Share on other sites

It's not an option to use it 3 times? There's not a function that gets 3 fields from a row.Just get the entire row and if you're looking at the first row then save the fields into variables. You can use a counter to figure out which row you're on, or better yet just set the variables if they aren't already set.
With $i=1; at top and $i++; at end of my while loop I set now:
if ($i <= 1)						{						$firstSlideId = $slidesId;						$firstSlide = $slidesImg;						$firstSlideText = $slidesText;						}

to get all the rows. Does the trick pretty well. Thanks a lot...Son

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...