PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello
I am new to php and it took me hours to write a script in order to display the duty nightpharmacies in my town in accordance with the day of the week.
Although it is now complete and seems to be working I have a problem. Above the table showing the pharmacy, its phone number and address, there appears number "1" with no reason. You can see it yourself at http://dene.paniad.org/1111.php.
Here is the code
<?php
mysql_connect("localhost", "db-user", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
mysql_query("SET NAMES 'latin5'");
echo "<table border='1'>";
$s=date("H");
$d=date("D");
if ($d=="Mon" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='4'") or die(mysql_error());
}
elseif ($d=="Mon" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='7'") or die(mysql_error());
}
elseif ($d=="Tue" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='7'") or die(mysql_error());
}
elseif ($d=="Tue" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='8'") or die(mysql_error());
}
elseif ($d=="Wed" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='8'") or die(mysql_error());
}
elseif ($d=="Wed" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='6'") or die(mysql_error());
}
elseif ($d=="Thu" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='6'") or die(mysql_error());
}
elseif ($d=="Thu" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='1'") or die(mysql_error());
}
elseif ($d=="Fri" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='1'") or die(mysql_error());
}
elseif ($d=="Fri" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='2'") or die(mysql_error());
}
elseif ($d=="Sat" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='2'") or die(mysql_error());
}
elseif ($d=="Sat" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='5'") or die(mysql_error());
}
elseif ($d=="Sun" && $s<="8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='5'") or die(mysql_error());
}
elseif ($d=="Sun" && $s>"8") {
echo $result = mysql_query("SELECT * FROM nobetci_pazarcik
WHERE id='4'") or die(mysql_error());
}
Christopher wrote:Put the data/time information for each pharmacy in the database and use a single select to find all pharmacies for the current data/time.
I've added date/time into the database. Can you tell me how to use a "single" select for the current time? Can you write an example line?
What did you put in your database? You probably need two tables -- pharmacy and pharmacy_hours. You would search for matches where the current date/time are between the open/close time in a pharmacy_hours record. You would join with the pharmacy table to get the pharmacy information.
SELECT pharmacy.Eczane, pharmacy_scheule.* FROM pharmacy_schedule JOIN pharmacy ON pharmacy_schedule.pharmacy_id=pharmacy.id WHERE pharmacy_schedule..day='$day' AND pharmacy_schedule.open_time>='$time' AND pharmacy_schedule.close_time<='$time';
Thank you very much for your help. While waiting I tried something different. I removed "echo"s from the beginnings of the lines and number 1 disappeared. I am not sure if it will work like this. Let's wait and see. There are 8 pharmacies and a different one is on duty each day. The order changes every week. So, I am planning to change the id's every week.
hasanoca wrote: The order changes every week. So, I am planning to change the id's every week.
That is a poor idea, you should add a column called `order` and ORDER BY `order` to your queries.
Imagine if your phone number & address changed every week. All these IDs and numbers in our lives are confusing enough. No need to switch them up every week.
It would especially be bad if someone posted an order for pharmacy # 3 but at the same time you happened to be changing the IDs, and that person never got their medecine