kingofkya Posted June 11, 2007 Share Posted June 11, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/55179-solved-query-help/ Share on other sites More sharing options...
trq Posted June 11, 2007 Share Posted June 11, 2007 Sorry, your problem is not at all clear. Quote Link to comment https://forums.phpfreaks.com/topic/55179-solved-query-help/#findComment-272749 Share on other sites More sharing options...
kingofkya Posted June 11, 2007 Author Share Posted June 11, 2007 don't know how to make a working query to search each field individually so if i want a report for one day it returns all the feild this that date but if you also searched by job it would give all records for that day that were on that job Quote Link to comment https://forums.phpfreaks.com/topic/55179-solved-query-help/#findComment-272755 Share on other sites More sharing options...
pocobueno1388 Posted June 12, 2007 Share Posted June 12, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55179-solved-query-help/#findComment-272758 Share on other sites More sharing options...
kingofkya Posted June 12, 2007 Author Share Posted June 12, 2007 thanks very much problem solved Quote Link to comment https://forums.phpfreaks.com/topic/55179-solved-query-help/#findComment-272764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.