Jump to content

[SOLVED] Query help


kingofkya

Recommended Posts

ok i need help making a query that will search all the fields with a different variable, but also determine if their is anything in and if there in not anything it won't search by it

 

Hears what i have the variables that begin with qby then search a field named the same but without a qby

 

 

 

 

<html>

</html>

<head>

<title>PHP</title>

</head>

<body>

Data Summery

<?php

 

 

 

 

$username="XXXXXXXXXXXXXXXX";

$password="XXXXXXXXXXXXXXXX";

$database="XXXXXXXXXXXXXXXX";

 

$qbyname=$_POST['name'];

$qbywage=$_POST['wage'];

$qbydate=$_POST['date'];

$qbyjob=$_POST['job'];

$qbytype=$_POST['type'];

$qbydes=$_POST['des'];

$qbyhours=$_POST['hours'];

 

 

// name wage date job type des hours

 

mysql_connect(localhost,$username,$password);

mysql_select_db($database) or die( "Unable to select database");

 

 

$query = ("SELECT * FROM timecard");

$data = mysql_query($query);

 

 

while($info = mysql_fetch_array( $data ))

{

 

 

$name =  '';

$date =  '';

$wage =  '';

$job =  '';

$type =  '';

$des =  '';

$hours = '';

 

//Seperate array in to variables

 

$name = $info['name'];

$date = $info['date'];

$wage = $info['wage'];

$job = $info['job'];

$type = $info['type'];

$des = $info['des'];

$hours = $info['hours'];

 

 

 

 

print '<table border="1" cellpadding="0" cellspacing="0" rules="none" style="border-collapse: collapse" bordercolor="#111111" width="100%">';

print '<tr>';

print '<td width="50%">';

print '<p align="center">Name:';

print '</td>';

print '    <td width="50%">';

print '    <p align="center">Wage: ';

 

print $wage;

 

print '</td>';

print '  </tr>';

print '  <tr>';

print '    <td width="50%">';

print '    <p align="center">Date: ';

 

print $date;

 

 

print '    <td width="100%"';

print '    <p align="center">Job: ';

 

print $job;

 

print '</td>';

print '  </tr>';

print '  <tr>';

print '    <td width="100%" colspan="2">';

print '    <p align="left">Description: <br>';

 

print $des;

 

print '</td>';

print '  </tr>';

print '  <tr>';

print '    <td width="50%">';

print '    <p align="center">Type: ';

 

print $type;

print '</td>';

print '    <td width="50%">';

print '    <p align="center">Hours:';

 

print $hours;

print '</td>';

print '<tr>';

print '    <td width="100%" colspan="2">';

print '    <p align="center">Amount Due: ';

 

 

$amountdue=$wage*$hours;

print $amountdue;

$grandhours = $hours+$grandhours;

$grandtotal = $grandtotal+$amountdue;

$amountdue = 0;

$hours = 0;

print '  </tr>';

 

}

 

 

mysql_close();

 

 

 

?>

 

</table>

 

 

<?php

print '    <p align="center">Total Amount Due: ';

print $grandtotal;

 

print '    <p align="center">Total Hours Worked: ';

 

print $grandhours;

?>

 

 

 

</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/55179-solved-query-help/
Share on other sites

You could do something like this:

 

<?php

$query = "SELECT * FROM tbl WHERE 1";

if ($name) $query .= " AND name='$name'";
if ($wave) $query .= " AND wage='$wage'";
//....and so on

$result = mysql_query($query);

?>

 

That way it will only search for the form fields that are filled in, and also take in account every input they want to search for.

 

 

Link to comment
https://forums.phpfreaks.com/topic/55179-solved-query-help/#findComment-272758
Share on other sites

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.