Jump to content

[SOLVED] PHP query question


182x

Recommended Posts

Hey guys,

 

I am trying to create a query in order to dynamicly popular a listbox however I am trying to fill the listbox with years such as 2007 etc based on if they are stored in the data base. The problem is that two tables have to be checked that have no relation to eachother but this caues the problem of duplication so if both tables have 2007 it will appear in the list more than once.

 

I was just wondering if there is a way round this? Thanks.

 


$years= "SELECT * FROM table1;
$qyears = mysql_query($years, $link_id) or die(mysql_error());


$years2= "SELECT * FROM table2;
$qyears2 = mysql_query($years2, $link_id) or die(mysql_error());

if (mysql_num_rows($qyears2) > 0 || mysql_num_rows($qyears1) > 0)
{
?>
<select name="years">
<?php

//don't know what do do here
while($row = mysql_fetch_assoc($qyears))
{
?>
  <option value="<?php echo $row['year']; ?>"><?php echo $row['year']; ?></option>
<?php
}
}
?>
</select>

Link to comment
https://forums.phpfreaks.com/topic/62004-solved-php-query-question/
Share on other sites

Just give this a try for me, dont know if it will work on MYSQL:

 

$years= "SELECT DISTINCT(year) FROM table1,table2";
$qyears = mysql_query($years) or die(mysql_error());

?>
<select name="years">
<?php

//don't know what do do here
while($row = mysql_fetch_assoc($qyears))
{
?>
  <option value="<?php echo $row[$qyears]; ?>"><?php echo $row[$qyears]; ?></option>
<?php
}
}
?>
</select>
[/quote]

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.