Jump to content

[SOLVED] How to pull specific rows


kryppienation

Recommended Posts

Ok, This is prob a very simple thing to do but i don't know how. I am pulling info from a database and trying to make a random selection of the choices that are ok with my sql. In the example i have here, there are a total of 5 fish in the database that match my query. I need to now randomly select one of the results. I'm not sure how to do that, can anyone give me a hand? I left a copy of the code, and the output of the 5 fish in the database that were ok with the query.

 

 

 

Thanks Everyone  ;D

 

 

$selectfishsql = 'select * from fish where areacaught = 1 and rodused = 1';


DB::connect($DB_database);
$selectfish = DB::query($selectfishsql, "select fish rod 1 area 1.");
DB::close();

echo '<table border="1">';
while ($row = mysql_fetch_assoc($selectfish)) {


$fishid = $row['fid'];
$fishname = $row['fishname'];
$areacaught = $row['areacaught'];
$rodused = $row['rodused'];



echo '<tr><td>' . $fishid . '</td>';
echo '<td>' . $fishname . '</td>';
echo '<td>' . $areacaught . '</td>';
echo '<td>' . $rodused . '</tr><p>';



  }

echo '</table>';

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/130847-solved-how-to-pull-specific-rows/
Share on other sites

i changed it to try that and it gave me an error. included is the code and error

 

 

$selectfishsql = 'SELECT * FROM fish WHERE areacaught = 1 AND rodused = 1 LIMIT 1 ORDER BY RAND()';

DB::connect($DB_database);
$selectfish = DB::query($selectfishsql, "select fish rod 1 area 1.");
DB::close();

 

[attachment deleted by admin]

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.