Jump to content

Help checking if numbers are in a database


patstantwtf

Recommended Posts

Hello!

 

I need to loop through a list of numbers and check if they are present in a column in a database or not.

 

I'm having a hard time figuring out how to check the column value by value and compare to a incrementing $i value.

 

here is my query...

	$query2 = mysql_query("SELECT * FROM video");
$column = mysql_fetch_array($query2);
echo $column2['cable_number'];

this only echoes me the first ['cable_number'] in the database. i need to get every single one, and perform actions on each one as they come through.

 

and here is my for() statement

	
for($i=100;$i<=$highest;$i++){
check if $i is in the database.
             if it is(do something)
             if it isn't(do something)
}

 

i need to use that $i each iteration and see if it's present in the 'cable_number' column in the database. then i do something and continue on with the next i$ value.

 

 

 

I would just create a range using the highest and then use that in an IN() statement in mysql, something like:

 

$range = range(100, $highest);
$query2 = mysql_query('SELECT * FROM video WHERE cable_number IN(' . implode(',', $range) . ')');

while ($row = mysql_fetch_assoc($query2)) {
     echo $row['cable_number'] . ' was in the range! Hooray!<br />';
}

 

Which should be a bit more efficient then the other route. Not sure if this is what you were looking for, however.

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.