Jump to content

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

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.