Quote:
Originally Posted by Old Pedant
I think Mishu is giving bad advice on this one. Yes, you *CAN* do it the way he says, but it's not optimal. Say you had 100,000 records in your table. And only 7 of them had the active flag equal to 1.
With his solution, MySQL has to send *ALL 100,000 ROWS* to PHP and then PHP simply throws away all but those 7.
The better way is to do this in the SQL query:
Code:
$sql = "SELECT * FROM mybb_forms WHERE IFNULL(active,0) = 1";
$data = mysql_query( $sql ) or die( mysql_error() );
... rest of code as you have it...
You don't need to use the IFNULL( ) function if that active field is *NEVER* null.
Then you could just do
Code:
$sql = "SELECT * FROM mybb_forms WHERE active = 1";
|
PHP Code:
<?php
mysql_connect("localhost", "", "");
mysql_select_db("");
?>
<html>
<p>Here at HabFab, we're always looking for new staff to help keep our sites running. Without the staff of HabFab, we wouldn't be open. Fancy working for us? The below job applications are currently open. Remember you must be registered on our forum in order to apply for any job position. Simply click the job that takes your fancy and fill in the application form! You will be notified via Private Message on the forum if you have been successful, so be sure to check your private messages! We wish you the best of luck in your application!</p><br>
</html>
<?php
$sql = "SELECT * FROM mybb_forms WHERE IFNULL(active,0) = 1";
$data = mysql_query( $sql ) or die( mysql_error() );
$data = mysql_query("SELECT * FROM mybb_forms")
or die(mysql_error());
$info = mysql_fetch_array( $data );
while($info = mysql_fetch_array( $data ))
{
Print "<a href=http://habfab.com/forum/jobs.php?id=".$info['form_id'] . " target=_blank>" .$info['name'] . "</a><br><br>";
}
?>
I've now got that but it still shows all.
Thanks
~ David