help with database php

A

Anonymous

Guest
i am trying to make a webpage where you can chhose a month from a dropdown menue and the write the day in a txt box. when view is clicked it shows the data record according to a table assined by the dropmenue and record from the txt box
 
Hi, can you please make the question more descriptive. Give examples if you must.

thanks.
 
it is a databse with 12 tables for months of the year and each yable has a record for each day in that month. basicly u type a number in a text box between 1 and 30(for days) then you select a month from a drop meneu. when you press submit . it loads record from the table nemed according to the month choesen from the menue. does that make it a b it clearer
 
what code do i need to make it. i have the interface ready but the actual php is what i am stuck with.
 
First you have to make the tables and the records, then make a database connection. something like

Code:
<?php 

// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.

// Set the database access information as constants.
define ('DB_USER', '');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'yourdb');

// Make the connnection and then select the database.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>

and paste it to a php file, where you can just call it when you need it.

then you must have a form to get the inputs of the user, like month and day, right? after that redirect or pass the inputs to the same page or you can just past it to another page that contains the query.



first transfer these inputs on variables

Code:
$mnth = $_POST['month'];
$dy = $_POST['day'];

then you can use these variables in your query

Code:
$query = "SELECT * FROM '$mnth' WHERE day='$dy'";
$result = mysql_query ($query);

if (mysql_num_rows($result) == 0){
 echo "<tr bgcolor=#FFFFFF><td colspan=5><font size=2 face=Verdana, Arial, Helvetica, sans-serif>There are no records</font></td></tr>";
}

else {

while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
?>

of course you have to close all the "{" with "}"

and do your way of presenting the records.

use this to get a column from a db <?php echo $row['day'];?>

Question, why do you have to make separate tables for the months? and have days there?

by the way, you need to study php first, ok?

Swirlee you want to comment on this? Did i solve the problem?
 
well i understood most of it expet the first part which i don't understand. i am trying to learn php. and so far i have learnt quite a lot. :D but i could still learn more
 
Back
Top