-3

Okay here is the code im using quite simple stuff basicly it currently pulls one random profile pic along with the users first and last name.

Works like a charm the only thing is how can I make it pull more then at a time

  $query = $db->query("SELECT * FROM `content` ORDER BY RAND() LIMIT 1");

  while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
  $FirstName = $row['FirstName'];
  $LastName = $row['LastName'];
  $ProfilePic = $row['ProfilePic'];
  $AccountNumber = $row['AccountNumber'];

  echo '<a href="Http://MyUrl.Com/Profile.php?AccountNumber=';
  echo $AccountNumber;
  echo '"><img src="http://MyUrl.Com/Content/';
  echo $ProfilePic;
  echo '" width="89" height="117" alt="" /></a><span class="des"><br><a             href="Http://MyUrl.Com/Profile.php?AccountNumber=';
  echo $AccountNumber;
  echo '#">';
  echo $FirstName .' '. $LastName;
  echo '</a></span>';

}

So it pulls one account perfect now I want it where it will pull 8 at once that way I can have $FirstName1 = $row['FirstName']

The reason im doing it this way is because of a formating error so please dont try to give it to me in a loop pull formate or anything just how can I repeat this 8 times without breaking the while loop

bush man
  • 147
  • 2
  • 2
  • 8

1 Answers1

3

I'm not sure I understand your question? You can pull more than 1 result by changing LIMIT 1 to LIMIT 8 in the very first line of your code:

$query = $db->query("SELECT * FROM `content` ORDER BY RAND() LIMIT 8");
Wojciech Zylinski
  • 1,995
  • 13
  • 19
  • But then how do I reference each one cause like right now since its only pulling one the variable i use is firstname what would it be for the 3rd one for example Firstname3??? – bush man Jan 02 '13 at 03:03
  • Where do you use $FirstName and $LastName variables? If only inside the loop, then you don't need to change anything in your code, apart from LIMIT 1 to LIMIT 8. PDO will fetch 8 records from MySQL and display each on your page. – Wojciech Zylinski Jan 02 '13 at 03:06
  • well the issue is if I runn that its formated all wired cause there needs to be all the photos then a
    and then all the names but right now I have image then name then image then name then image then name
    – bush man Jan 02 '13 at 03:13