[RESOLVED] Mysql multiple rows and separate using php
I am trying to find a way to pull multiple rows from a database and than be able to separate the rows and use them in php.
PHP Code:
$result = mysql_query("SELECT url, image, placement FROM advert
WHERE user='1'") OR die(mysql_error());
//This grabs 3 rows with placement name equal to 'sideadtop','sideadmiddle','sideadbottom'
I am trying to get the url and image values for each ad placement value. Should I be using mysql to pull individual rows or use php to separate them if possible. Or is there a better way to do this?
Not sure if this is what you are asking, but typically you create your SQL to retrieve all the desired rows, then use a while() loop to process each result row:
PHP Code:
$sql = "SELECT blah blah blah...";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
// do stuff with $row to process/output this result row
}
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
and use them within another function... I need to get speficic "url" field based on the placement field.
So if placement == "sideadtop" I would like to get the url that is in the row of that placement.
I would like to know if I have to do this with individual calls to MYSQL getting one row ata time or if there is a way to get all 3 rows and seperate them as needed?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks