Jump to content

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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.