Jump to content

Simple PHP & Mysql Program ! Need your help


BinaryPax

Recommended Posts

Hello Brothers

It's My first time here on this amazing forum.

and i think i am gonna be stuk with you here for a long time :)

 

Well, i wrote a simple php code thats supposed to show me mission ( tables : A, B, C, D ) That have been made within 2 dates that the user chose :

 

Just to explain things well:

I have a db that contain tables ( A, B,C,D... that represents missions ), each table contains the traitements that have been made with the date of the treatement.

 

i have used in a previous page a datepicker to chose 2 dates, date1 and date2. and right after send them to a page with a simple POST Form.

 

my program should search in each table for the number of treatments that have been made between the 2 dates, i used a simple Count() as you will see.

 

because my programe is only supposed to show to the user the missions ( tables ) that we have been working on between the 2 dates.

 

after i just check if the numberofrows is > 0. as simple asthat

my problem is that my program work, and return results, but the probleme is that it returns correct and some incorrect results. and i could not understand why, it may be very simple because i'm a verrry beginner.

so if you could help, i will really appreciate it :)

 

here is the code of the page :



<?php
include 'connect.php';
$date1   = $_POST['date1'] ; // recuperation de la date 1 et 2
$date2   = $_POST['date2'] ; 
$dateOfToday = date("Y-m-d");   //La Date Du Jour
$A1 = "SELECT count(id) FROM `A` WHERE date BETWEEN 'date1' AND 'date2'";
$ResultA1 = mysql_query($A1);
$B1 = "SELECT count(id) FROM `B` WHERE date BETWEEN 'date1' AND 'date2';";
$ResultB1 = mysql_query($B1);
$C1 = "SELECT count(id) FROM `C` WHERE date BETWEEN 'date1' AND 'date2'";
$ResultC1 = mysql_query($C1);
$D1 = "SELECT count(id) FROM `D` WHERE date BETWEEN 'date1' AND 'date2'";
$ResultD1 = mysql_query($D1);
$E1 = "SELECT count(id) FORM `E` WHERE date BETWEEN 'date1' AND 'date2'";
$RsultE1 = mysql_query($E1);
$F1 = "SELECT count(id) FROM `F` WHERE date BETWEEN 'date1' and 'date2'";
$ResultF1 = mysql_query($F1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Stats</title>
 <style type="text/css">
<!--
body {
background-color: #E6EAF3;
margin-left: 00px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="css/newstyles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.Style14 {
color: #FFFFFF;
font-weight: bold;
}
.Style16 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>
<style type="text/css">
<!--
.ds_box { background-color: #FFF;
border: 1px solid #000;
position: absolute;
z-index: 32767;
}
.style17 {font-size: large}
-->
</style>
</head>
<body>
<p> Les Missions Traitées entre le <?php echo "$date1" ?> Et <?php echo "$date2" ?> : </p>
<table>
<tbody>
 <tr>
  <td>
   <p>
    <?php if ($ResultA1 > 0)


     { echo 'Mission A'; 
     } ?>
   </p>
  </td>
 </tr>
 <tr>
  <td>
   <p>
    <?php if ($ResultB1 > 0)
     { echo 'Mission B'; 
     } ?>
    </p>
   </td>
  </tr>
 <tr>
<td>
<p>
<?php if ($ResultC1 > 0)
{ echo 'Mission C'; 
}?>
</p>
</td>
</tr>
<tr>
<td>
<p>
<?php if ($ResultD1 > 0)
{ echo 'Mission D'; 
}?>
</p>
</td>
</tr>
<tr>
<td>
<p>
<?php if ($ResultE1 > 0)
{ echo 'Mission E'; 
}?>
</p>
</td>
</tr>
<tr>
<td>
<p>
<?php if ($ResultF1 > 0)
{ echo 'Mission F'; 
}?>
</p>
</td>
</tr>
</tbody>
</table>
</body>


</html>

Link to comment
Share on other sites

You typoed one of the variable names (in the first part of the script).

 

But really you shouldn't have 6 tables for what sounds like the same type of data. You only need one table: it looks exactly the same as your A-F tables but it has a column indicating what type of mission it is. And if you think the missions could ever change then there's a second table with the list of possible missions (and the other table has a foreign key off to it). In fact that's just a good idea anyways.

list of missions

id | mission
---+--------
 1 | A
 2 | B
 3 | C
 4 | D
 5 | E
 6 | F

the new table

fields... | mission
----------+--------
    ...   | 1        \
    ...   | 1         \_  All "A" missions
    ...   | 1         /
    ...   | 1        /
    ...   | 2        \
    ...   | 2         \_  All "B" missions
    ...   | 2         /
    ...   | 2        /

Edited by requinix
Link to comment
Share on other sites

You typoed one of the variable names (in the first part of the script).

 

But really you shouldn't have 6 tables for what sounds like the same type of data. You only need one table: it looks exactly the same as your A-F tables but it has a column indicating what type of mission it is. And if you think the missions could ever change then there's a second table with the list of possible missions (and the other table has a foreign key off to it). In fact that's just a good idea anyways.

list of missions

id | mission
---+--------
1 | A
2 | B
3 | C
4 | D
5 | E
6 | F

the new table

fields... | mission
----------+--------
   ...   | 1        \
   ...   | 1         \_  All "A" missions
   ...   | 1         /
   ...   | 1        /
   ...   | 2        \
   ...   | 2         \_  All "B" missions
   ...   | 2         /
   ...   | 2        /

 

 

sorry but i couldn't understand what you meant by "You typoed one of the variable names (in the first part of the script)." wich variable ?

 

and about the tables, no each table is for a specific mission, and each table contains the dates of the treatements that have been made within a a specific mission. so i had to use all of them.

 

but really i dont know why i get some wrong results, !! :s

Link to comment
Share on other sites

$RsultE1

 

and about the tables, no each table is for a specific mission, and each table contains the dates of the treatements that have been made within a a specific mission. so i had to use all of them.

Perhaps, but that's not what I'm talking about. This exact purpose aside and focusing just on the tables specifically, don't they all contain the same type of data? All have ID numbers, names, dates, and so on? Or put another way do all the tables have the same columns and structure?

If so then you have a bunch of unnecessary tables: you can put all the same data into one table and add a column that lets you keep track of what mission each row is for. Having just one table would make this all a lot easier, right?

Edited by requinix
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.