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
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]

Link to comment
Share on other sites

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.