
naykidd
Members-
Posts
16 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
naykidd's Achievements

Newbie (1/5)
0
Reputation
-
I'm trying to work out the sum of a set of values (named price in my table) in a multi dimensional array, an array generated from search results ($searchResults). When i echo the contents of this array (or what i assume is an array), or try to use the 2 examples at http://www.phpfreaks.com/forums/index.php/topic,215109.0.html i get the following "array_reduce() [function.array-reduce]: the first argument should be an array in..... etc etc" Here is the code I use function multi_array_sum($total, $next) { $total += $next['price']; return $total; } $totalCost = array_reduce($searchResult, 'multi_array_sum'); echo $totalCost I also have tried $row, $row1 etc which wont work as it isn't filtered through my search results, but i tested it to see the output (row is used to print my results, i use while ($row1 = mysql_fetch_array($searchResult)) { echo $row1['price'] } ) is there a function i should be using that will work with $searchResult to get the price and add it up? thanks
-
Im wondering if anyone could offer a solution, i'm having a nightmare with a submit form. Im trying to make an invoice system, using a 3rd party system that im modifying (Tried to look on their site but they have no help system). I need to add items to the order, AND post them to an sql table whilst automatically working out the VAT + Total cost I then need to be able to add more items, and them also submit to the sql table in another row (using Submit2, its kind of a form within a form) Finally, when i go to submit the final page, the page submits the customers name/invoice/address details etc to another table via $_POST, and then brings it all up on the invoice page (I use WHERE invoiceno="" to bring back all the seperate parts of the order from the database) So far, I can get the different items to come up on the invoice, but they wont store via a $_POST method (I get an error) and if i use anything but a loop, like just a variable, the item does store in the table when i submit it, but it wont remember the item for the invoice page, and the prices all become the same when i add multiple items! I'd love to get some feedback, i've been php coding for a while now, and this is one i'm really struggling with! Theres a config file this code links too, but its not needed to see whats going on so ive left it out! I know the update function won't work at the moment either, but i'm working on that. Thanks, <?php /************************************************************************/ /* PHP InvoiceIt v1.0 */ /* =========================== */ /* */ /* Written by Steve Dawson - http://www.stevedawson.com */ /* Freelance Web Developer - PHP, MySQL, HTML programming */ /* */ /* This program is free software. You can redistribute it and/or modify */ /* but please leave this header intact, thanks */ /************************************************************************/ include "config.php"; require_once("Connections/connection.php"); error_reporting (E_ALL ^ E_NOTICE); error_reporting (E_ALL ^ E_NOTICE); ## The processing function thingy ma jig. function processform() { global $HeaderDistance; global $BorderColour; global $TableBGcolour; global $PageTitle; global $CurrencyUnit; global $InvoiceSignature; global $DisplayVat; global $TaxName; global $VatRate; global $vat_at; global $customer_id; global $customer_address; global $customer_name; global $date; global $order; global $price; global $notes; ?> <HTML> <HEAD> <TITLE>PHP InvoiceIt - Invoice Created</TITLE> <LINK REL="STYLESHEET" HREF="invoice.css"> </HEAD> <BODY> <img src="blank.gif" width="1" height="<?php print $HeaderDistance; ?>"> <DIV align="center"> <?php print "$part"; ?> <TABLE border="0" width="600"> <tr> <TD valign="top" colspan="2"> <table> <tr> <td align="left"> To:<br> <?php print $customer_name; ?><br> <?php print str_replace("\n", "<br>", $customer_address); ?> </td> </tr> <tr> <td align="right"> <b>Date:</b> <?php print "$date"; ?> </td> </tr> <tr> <td align="right"> <b>Ref:</b> <?php print "$customer_id"; ?> </td> </tr> <tr> <td> <br><br><table width="100%" CELLPADDING="2" CELLSPACING="0" border="1" bordercolor="<?PHP print "$BorderColour"; ?>"> <tr bgcolor="<?PHP print "$TableBGcolour"; ?>"> <th>Product</th> <th>Cost</th> <th><?PHP print "$TaxName"; ?></th> <th>Total</th> </tr> <tr> <td><img src="blank.gif" width="450" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> </tr> <?php $tot_cost = "0"; $tot_vat = "0"; $tot_price = "0"; for($l=0; $l<sizeof($order); $l++){ if(!strlen($order[$l]) && $l == (sizeof($order)-1)) { continue; } ?> <tr> <td><?php print $order[$l]; ?></td> <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?></td> <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]-($price[$l]/($vat_at+100)*100), 2); ?></td> <td align="right" width="50"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l],2); ?></td> </tr> <?php $tot_cost += $price[$l]/($vat_at+100)*100; $tot_vat += $price[$l]-($price[$l]/($vat_at+100)*100); $tot_price += $price[$l]; } ?> <tr> <td colspan="4"><?php if($DisplayVat == "Y") { print "<i>$TaxName charged at a rate of $vat_at%</i>"; } else print "<img src=\"blank.gif\" width=\"1\" height=\"14\">";?></td> </tr> </table> <br> <table align="right" width="0" CELLPADDING="2" CELLSPACING="1" border="1" bordercolor="<?PHP print "$BorderColour"; ?>"> <tr> <td width="60" align="right"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_cost,2); ?></b></td> <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_vat,2); ?></b></td> <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_price,2); ?></b></td> </tr> </table> <br> <br><br><br><?php print tag($notes); ?> <br> <br> <?php print "$InvoiceSignature"; ?> </td> </tr></table></TD></TR></TABLE> </DIV> </BODY> </HTML> <?php } function mainform() { ///////////////////////////////////////////////// variables $customer_id = $_POST['invoice']; $customer_id = $_POST['invoiceno']; $part = $_POST['part']; $tot_cost = $_POST['totcost']; $tot_vat = $_POST['totvat']; $tot_price = $_POST['totprice']; $description = $_POST['description']; $Submit = $_POST['Submit']; $Submit2 = $_POST['Submit2']; ////////////////////////////////////// $query = sprintf("SELECT * FROM invo where ID='$upd'"); $result = @mysql_query($query); //tells the database $rowUpdate = mysql_fetch_array($result); //fetches the result ////////////////////////////////////// /////////////////////////////// The following checks if there is stuff in every field and not in the hidden update field global $HeaderDistance; global $BorderColour; global $TableBGcolour; global $PageTitle; global $CurrencyUnit; global $DisplayVat; global $TaxName; global $VatRate; global $InvoiceSignature; global $n_order; global $n_price; global $vat_at; global $customer_id; global $customer_address; global $customer_name; global $date; global $order; global $price; global $notes; ?> <HTML> <HEAD> <TITLE>PHP InvoiceIt - Create the Invoice</TITLE> <LINK REL="STYLESHEET" HREF="invoice.css"> </HEAD> <BODY><img src="blank.gif" width="1" height="<?php print $HeaderDistance; ?>"> <DIV align="center"> <TABLE WIDTH="90%" BORDER="0" CELLPADDING="2" CELLSPACING="2" ALIGN="CENTER"> <TR> <TD valign="top" colspan="2"><H4 align="center"><?PHP print $PageTitle; ?></H4> <br> <form id="form1" name="form1" method="post"> <table> <tr> <td align="left"> To:<br> <input type="text" name="customer_name" size="38" value="<?php if($customer_name) { print tag($customer_name); } else { print "Insert Customer Name"; } ?>"> <br> <textarea name="customer_address" rows="5" cols="40"><?php if($customer_address) { print $customer_address; } else { print "Insert Customer Address"; } ?></textarea> </td> </tr> <tr> <td align="right"> <b>Date:</b> <input type="text" name="date" size="15" value="<?php if($date){ print tag($date); } else { print date("d/m/Y"); } ?>"> </td> </tr> <tr> <td align="right"> <b>Ref Number:</b> <input type="text" name="customer_id" size="15" value="<?php if($customer_id){ echo $rowUpdate['invoice']; print tag($customer_id); } else { print "Customer Ref"; } ?> "> </td> </tr> <tr> <td> <table width="100%" CELLPADDING="2" CELLSPACING="0" border="1" bordercolor="<?PHP print "$BorderColour"; ?>"> <tr bgcolor="<?PHP print "$TableBGcolour"; ?>"> <th>Product</th> <th>Description</th> <th>Cost</th> <th><?PHP print "$TaxName"; ?></th> <th>Total</th> </tr> <tr> <td><img src="blank.gif" width="400" height="14"></td> <td><img src="blank.gif" width="110" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> <td><img src="blank.gif" width="60" height="14"></td> </tr> <?php $tot_cost = 0; $tot_vat = 0; $tot_price = 0; for($l=0; $l<sizeof($order); $l++){ ?> <input type="hidden" name="order[<?php print $l; ?>]" value="<?php print tag($order[$l]); ?>"> <input type="hidden" name="price[<?php print $l; ?>]" value="<?php print tag($price[$l]); ?>"> <tr> <td><?php print $part; ?></td> <td><?php print $description; ?></td> <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]/($vat_at+100)*100, 2); ?></td> <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l]-($price[$l]/($vat_at+100)*100),2); ?></td> <td align="right"><?php print "$CurrencyUnit"; ?><?php print number_format($price[$l],2); ?></td> </tr> <?php $tot_cost += $price[$l]/($vat_at+100)*100; $tot_vat += $price[$l]-($price[$l]/($vat_at+100)*100); $tot_price += $price[$l]; $order2 = $order[$l]; $order2 = $_POST['order']; } ?> <form id="form2" name="form2" method="post"> <b>Part:</b> <input type="text" name="part" size="15" value="<?php echo $rowUpdate['part']; ?> "> <input type="text" name="description" size="15" value="<?php echo $rowUpdate['description']; ?> "> <input name="Submit2" type="Submit" value="Submit2" class="button"></p> <?php if($Submit2){ /////////////////////////////////////////////////////// this inserts it $query = sprintf("INSERT INTO invo2 (part, invoiceno, totcost, totvat, description, totprice, order) values ('$part', '$customer_id', '$tot_cost', '$tot_vat', '$description', '$tot_price', '$order2')"); mysql_query($query)or die (mysql_error()); } {} ?> </FORM> <tr> <td> <input type="text" name="order[<?php print sizeof($order); ?>]" size="70"></td> <td align="right"><img src="blank.gif" width="60" height="14"></td> <td align="right"><img src="blank.gif" width="60" height="14"></td> <td align="right"><?php print "$CurrencyUnit"; ?> <input type="text" name="price[<?php print sizeof($price); ?>]" size="5"></td> </tr> <tr> <td colspan=4><?php if($DisplayVat == "Y") { print "<input type=\"hidden\" name=\"vat_at\" value=\"$VatRate\" size=\"4\"> <i>$TaxName charged at a rate of $VatRate%</i>"; } else print "<img src=\"blank.gif\" width=\"1\" height=\"14\">"; ?></td> </tr> </table> <table align="right" width="0" CELLPADDING="2" CELLSPACING="1" border="1" bordercolor="<?PHP print "$BorderColour"; ?>"> <br> <tr> <td width="60" align="right"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_cost,2); ?></b></td> <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_vat,2); ?></b></td> <td align="right" width="60"><b><?php print "$CurrencyUnit"; ?><?php print number_format($tot_price,2); ?></b></td> </tr> </table><br> <br> <br>Enter any additional notes:<br> <textarea name="notes" cols="100%" rows="5"><?php print "$notes"; ?></textarea> <br> <br><br> <?php print "$InvoiceSignature"; ?><br></td> </tr> <tr> <td><br> <br> <p align="center"><input name="action" type="submit" value="Update Invoice" class="button"> <input name="Submit" type="Submit" value="Submit" class="button"></p></td> </tr></table> </FORM> </TD> </TR> </TABLE> </DIV> </BODY> </HTML> <?php } if($Submit == "Submit"){ processform(); /////////////////////////////////////////////////////// this inserts it $query = sprintf("INSERT INTO invo (invoice) values ('$customer_id')"); mysql_query($query)or die (mysql_error()); } else {mainform();} ?>
-
Not sure if anyones had any ideas? I'm on the verge of rewriting the entire combo box form in a different method...
-
Thanks for looking Still doing the same, rather frustrating! Im not sure if itl help, but my MySQL has a tables which matches the name you pick to a column of models (so my table has about 700 listings in total, but only displays 20/30 at a time due to the make you select) each model has the make next to it (e.g. 312, 314, 316 will each have BMW next to it) The idea of the second statement is to pull through the model number when the make is set... It does this fine, as i can select any make, and the model will appear in the second box after refreshing (The page refreshes itself upon change of the first dropdown) Maybe this is why it's pulling the make through a second time? Or could this be due to the fact i have 2 option boxes in 1 form, although i've tried splitting it up and it just forgets everything when i press submit...
-
I changed it, its still just repeating the make and model the same.. <? if (isset($_POST['model'])) $model = $_POST['model']; echo $makech; ?><br><? echo $model; ?><br /><? session_destroy(); ?>
-
Basically, im trying to get 2 values from a PHP dropdown menu, to then use in a MySql query, but im having trouble retrieving them... I have Makes and Models, and currently, I can retrieve Make, and echo it so i know it exists, but i can't retrieve the Model, it just echos make again... The 2 tables are dynamically linked (Once a model is selected,the page refreshes and a make can be chosen depending on which model) I know how to take the variables and put them into the MySQL table, its just retrieving them! Heres what i have so far: require_once("Connections/connection.php"); session_start(); $make = $_POST['make']; if ($make){ $query = sprintf("SELECT * FROM car_model where car_model_id='$make'"); $result = @mysql_query($query); $rowModel = mysql_fetch_array($result); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <select name="make" onChange="document.forms[0].submit()"> <option value="" selected="selected">Select Make</option> <option value="AC" <?php if(!(strcmp(AC, $make))){echo "selected";}?>>AC</option> <option value="ALFA" <?php if(!(strcmp(ALFA, $make))){echo "selected";}?>>ALFA</option> <option value="AUDI" <?php if(!(strcmp(AUDI, $make))){echo "selected";}?>>AUDI</option> <option value="AUSTIN" <?php if(!(strcmp(AUSTIN, $make))){echo "selected";}?>>AUSTIN</option> <option value="AUSTIN-HEALEY" <?php if(!(strcmp(AUSTIN-HEALEY, $make))){echo "selected";}?>>AUSTIN-HEALEY</option> <option value="BMW" <?php if(!(strcmp(BMW, $make))){echo "selected";}?>>BMW</option> <option value="CATERHAM" <?php if(!(strcmp(CATERHAM, $make))){echo "selected";}?>>CATERHAM</option> <option value="CHEVROLET" <?php if(!(strcmp(CHEVROLET, $make))){echo "selected";}?>>CHEVROLET</option> <option value="CHRYSLER" <?php if(!(strcmp(CHRYSLER, $make))){echo "selected";}?>>CHRYSLER</option> <option value="CITROEN" <?php if(!(strcmp(CITROEN, $make))){echo "selected";}?>>CITROEN</option> <option value="DAEWOO" <?php if(!(strcmp(DAEWOO, $make))){echo "selected";}?>>DAEWOO</option> <option value="DAIHATSU" <?php if(!(strcmp(DAIHATSU, $make))){echo "selected";}?>>DAIHATSU</option> <option value="FIAT" <?php if(!(strcmp(FIAT, $make))){echo "selected";}?>>FIAT</option> <option value="FORD" <?php if(!(strcmp(FORD, $make))){echo "selected";}?>>FORD</option> <option value="HONDA" <?php if(!(strcmp(HONDA, $make))){echo "selected";}?>>HONDA</option> <option value="HYUNDAI" <?php if(!(strcmp(HYUNDAI, $make))){echo "selected";}?>>HYUNDAI</option> <option value="ISUZU" <?php if(!(strcmp(ISUZU, $make))){echo "selected";}?>>ISUZU</option> <option value="IVECO" <?php if(!(strcmp(IVECO, $make))){echo "selected";}?>>IVECO</option> <option value="JAGUAR" <?php if(!(strcmp(JAGUAR, $make))){echo "selected";}?>>JAGUAR</option> <option value="JEEP" <?php if(!(strcmp(JEEP, $make))){echo "selected";}?>>JEEP</option> <option value="JEEP" <?php if(!(strcmp(JEEP, $make))){echo "selected";}?>>JEEPA</option> <option value="LANCIA" <?php if(!(strcmp(LANCIA, $make))){echo "selected";}?>>LANCIA</option> <option value="LAND-ROVER" <?php if(!(strcmp(LAND-ROVER, $make))){echo "selected";}?>>LAND-ROVER</option> <option value="LDV" <?php if(!(strcmp(LDV, $make))){echo "selected";}?>>LDV</option> <option value="LEXUS" <?php if(!(strcmp(LEXUS, $make))){echo "selected";}?>>LEXUS</option> <option value="LOTUS" <?php if(!(strcmp(LOTUS, $make))){echo "selected";}?>>LOTUS</option> <option value="MAZDA" <?php if(!(strcmp(MAZDA, $make))){echo "selected";}?>>MAZDA</option> <option value="MCC" <?php if(!(strcmp(MCC, $make))){echo "selected";}?>>MCC</option> <option value="MERCEDES-BENZ" <?php if(!(strcmp(MERCEDES-BENZ, $make))){echo "selected";}?>>MERCEDES-BENZ</option> <option value="MG" <?php if(!(strcmp(MG, $make))){echo "selected";}?>>MG</option> <option value="MINI" <?php if(!(strcmp(MINI, $make))){echo "selected";}?>>MINI</option> <option value="MITSUBISHI" <?php if(!(strcmp(MITSUBISHI, $make))){echo "selected";}?>>MITSUBISHI</option> <option value="NISSAN" <?php if(!(strcmp(NISSAN, $make))){echo "selected";}?>>NISSAN</option> <option value="OPEL" <?php if(!(strcmp(OPEL, $make))){echo "selected";}?>>OPEL</option> <option value="PERODUA" <?php if(!(strcmp(PERODUA, $make))){echo "selected";}?>>PERODUA</option> <option value="PEUGEOT" <?php if(!(strcmp(PEUGEOT, $make))){echo "selected";}?>>PEUGEOT</option> <option value="PORSCHE" <?php if(!(strcmp(PORSCHE, $make))){echo "selected";}?>>PORSCHE</option> <option value="PROTON" <?php if(!(strcmp(PROTON, $make))){echo "selected";}?>>PROTON</option> <option value="RELIANT" <?php if(!(strcmp(RELIANT, $make))){echo "selected";}?>>RELIANT</option> <option value="RENAULT" <?php if(!(strcmp(RENAULT, $make))){echo "selected";}?>>RENAULT</option> <option value="ROVER" <?php if(!(strcmp(ROVER, $make))){echo "selected";}?>>ROVER</option> <option value="SAAB" <?php if(!(strcmp(SAAB, $make))){echo "selected";}?>>SAAB</option> <option value="SEAT" <?php if(!(strcmp(SEAT, $make))){echo "selected";}?>>SEAT</option> <option value="SKODA" <?php if(!(strcmp(SKODA, $make))){echo "selected";}?>>SKODA</option> <option value="SSANGYONG" <?php if(!(strcmp(SSANGYONG, $make))){echo "selected";}?>>SSANGYONG</option> <option value="SUBARU" <?php if(!(strcmp(SUBARU, $make))){echo "selected";}?>>SUBARU</option> <option value="SUZUKI" <?php if(!(strcmp(SUZUKI, $make))){echo "selected";}?>>SUZUKI</option> <option value="TALBOT" <?php if(!(strcmp(TALBOT, $make))){echo "selected";}?>>TALBOT</option> <option value="TOYOTA" <?php if(!(strcmp(TOYOTA, $make))){echo "selected";}?>>TOYOTA</option> <option value="TRIUMPH" <?php if(!(strcmp(TRIUMPH, $make))){echo "selected";}?>>TRIUMPH</option> <option value="TVR" <?php if(!(strcmp(TVR, $make))){echo "selected";}?>>TVR</option> <option value="VAUXHALL" <?php if(!(strcmp(VAUXHALL, $make))){echo "selected";}?>>VAUXHALL</option> <option value="VOLVO" <?php if(!(strcmp(VOLVO, $make))){echo "selected";}?>>VOLVO</option> <option value="VOLKSWAGEN" <?php if(!(strcmp(VOLKSWAGEN, $make))){echo "selected";}?>>VOLKSWAGEN</option> <option value="WESTFIELD" <?php if(!(strcmp(WESTFIELD, $make))){echo "selected";}?>>WESTFIELD</option> </select> <? $makch = $_POST['make']; ?> <select name="model"> <option value="">Select Model</option> <?php do { ?> <option value="<?php echo $rowModel['car_model_id']; ?>"><?php echo $rowModel['car_model']; ?></option> <?php }while ($rowModel = mysql_fetch_array($result)); ?> </select> <?php ?> <input class="button" type="submit" name="search" value="Search" /> </form> <br /> <? if (isset($_POST['model'])) $making = $_GET['rowModel']; echo "$makech"; ?><br><? echo "$model; session_destroy(); ?> Thanks
-
I tried to input your words too but seem to have failed, first search works but the second dropdown is always empty :/ Many thanks <? ///////////////////////////////// CONNECTION require_once("Connections/connection.php"); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="../stylesheet.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style9 { font-size: 14px } .style11 {font-size: 14px} .style1 { font-size: 18px } .style12 {font-size: 12px} .style131 { font-size: 14px; font-weight: bold; } </style> </head> <body> <table border='0' width 955 align=center> <tr> <td> <img src="../Images/banner.jpg" alt="Banner" width="955" height="100" /> </td> /////////////// SEARCH 1 *************** $query="SELECT Make FROM makes"; $result = mysql_query ($query);?> <p> </p> <p> <form enctype='multipart/form-data' METHOD=POST ACTION="pagetest.php"> <? echo "<select name='chooser'></option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[Make]>$nt[Make]</option>"; } echo "</select>"; echo "<input type='submit' value='submit' />"; echo "</form>"; ?> <br /> <br /> <? ////////////////////////// SEARCH 2 ************************ if (isset($_POST['chooser'])) echo "You Selected $chooser <br> Now choose a Model of $chooser <br><br>"; $query2="SELECT Model FROM makemodel WHERE Make = '$chooser'"; //Select the make associated with the model (E.g. ford brings up Escort, Fiesta etc.. $models = mysql_query($query2); if (!empty($chooser)): ?> <select name="mfinder"> <?php foreach ($chooser as $models): ?> <option name="<?php print $models; ?>"><?php print $models; ?></option> <?php endforeach; ?> </select> <?php else: ?> <select name="mfinder" disabled></select> <?php endif; if (isset($_POST['mfinder'])) { echo "You Searched for $chooser $mfinder"; $querys = sprintf("SELECT * FROM rossinis"); //selects all data from the database $results = @mysql_query($querys); //tells the database $row = mysql_fetch_array($results); //fetches the result $querys = " ORDER BY `Model`"; $searchSQL = "SELECT ID, Make, Model, Detail, Capacity, Year, Vs, Dia, Thick, Bore, Studs, Part, Price FROM rossinis WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['mfinder'])?"`model` LIKE '%{$mfinder}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`Model` LIKE '%{$mfinder}%'"; // use the model as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `id`"; // order by id $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); $size = 0; $cnt = 0; "</Center></td>"; echo "<tr>"; echo "<table border='0' width '955' align=center>"; echo "</tr>"; echo "<br>"; echo "<table border='1' width='955' align=center>"; echo "<tr>"; echo "<td><b>Make</b></td>"; echo "<td><b>Model</b></td>"; echo "<td><b>Detail</b></td>"; echo "<td><b>Capacity</b></td>"; echo "<td><b>Year</b></td>"; echo "<td><b>Vented/Solid</b></td>"; echo "<td><b>Diameter</b></td>"; echo "<td><b>Thickness</b></td>"; echo "<td><b>Disk Bore</b></td>"; echo "<td><b>Studs</b></td>"; echo "<td><b>Part Number</b></td>"; echo "<td><b>Price</b></td>"; echo "</tr>"; while ($row1 = mysql_fetch_array($searchResult)) { echo "<tr>"; echo "<td>".$row1['Make']."</td>"; echo "<td>".$row1['Model']."</td>"; echo "<td>".$row1['Detail']."</td>"; echo "<td>".$row1['Capacity']."</td>"; echo "<td>".$row1['Year']."</td>"; echo "<td>".$row1['Vs']."</td>"; echo "<td>".$row1['Dia']."</td>"; echo "<td>".$row1['Thick']."</td>"; echo "<td>".$row1['Bore']."</td>"; echo "<td>".$row1['Studs']."</td>"; echo "<td>".$row1['Part']."</td>"; echo "<td>".$row1['Price']."</td>"; } $cnt++; echo "</tr>"; echo "</table>"; echo "<br><br><br><br><br>"; } function removeEmpty($var) { return (!empty($var)); } session_destroy(); ?> </p>
-
Thanks! I've tried implementing it into my code but i think i've mistaken where it needs to go, im getting the form again, and now its not allowing me to make any selections, could you help in where id put your code? in mine the make of the car is known as $chooser and the model of the car is known as $mfinder, have you used $make and $model where i would use them then? I've been doing this all day though is nice to be getting somewhere finally!
-
Basicaly, the following brings up two dropdown menus of cars Firstly, you select the make, and hit select Then the models appear, according to the make. You then select the relative model, and hit select, generating a list of parts from the model This all goes well, but im trying to save the make from the first form to the second form so i can say "You searched for 'Make' 'Model' " I've been reading up all morning on Sessions, and i've got it to work setting a variable as a random word and making it appear, but i can't get my code to pick up the first choice as a variable, it will only say the model I understand i need to use something like the following i've written SOMEWHERE in my code.. $_SESSION['test0'] = $_POST['chooser']; but wherever i seem to put it, chooser is always blank however if i change chooser to "lemon" or something, and put the line $lemon = test or something above it, it works fine and says "You have chosen Test "make"" <? ///////////////////////////////// CONNECTION require_once("Connections/connection.php"); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="../stylesheet.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style9 { font-size: 14px } .style11 {font-size: 14px} .style1 { font-size: 18px } .style12 {font-size: 12px} .style131 { font-size: 14px; font-weight: bold; } </style> </head> <body> <table border='0' width 955 align=center> <tr> <td> <img src="../Images/banner.jpg" alt="Banner" width="955" height="100" /> </td> /////////////// SEARCH 1 *************** $query="SELECT Make FROM makes"; $result = mysql_query ($query);?> <p> </p> <p> <form enctype='multipart/form-data' METHOD=POST ACTION="pagetest.php"> <? echo "<select name='chooser'></option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[Make]>$nt[Make]</option>"; } echo "</select>"; echo "<input type='submit' value='submit' />"; echo "</form>"; ?> <br /> <br /> <? ////////////////////////// SEARCH 2 ************************ if (isset($_POST['chooser'])) echo "You Selected $chooser <br> Now choose a Model of $chooser <br><br>"; $query2="SELECT Model FROM makemodel WHERE Make = '$chooser'"; //Select the make associated with the model (E.g. ford brings up Escort, Fiesta etc.. $result2 = mysql_query ($query2); ?> <form enctype='multipart/form-data' METHOD=POST ACTION="pagetest.php"> <? echo "<select name='mfinder'></option>"; while($nt2=mysql_fetch_array($result2)){ echo "<option value=$nt2[Model]>$nt2[Model]</option>"; } echo "</select>"; echo "<input type='submit' value='submit' />"; echo "</form>"; if (isset($_POST['mfinder'])) { echo "You Searched for ".$_SESSION['test0']." $chooser $type $mfinder"; $querys = sprintf("SELECT * FROM rossinis"); //selects all data from the database $results = @mysql_query($querys); //tells the database $row = mysql_fetch_array($results); //fetches the result $querys = " ORDER BY `Model`"; $searchSQL = "SELECT ID, Make, Model, Detail, Capacity, Year, Vs, Dia, Thick, Bore, Studs, Part, Price FROM rossinis WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['mfinder'])?"`model` LIKE '%{$mfinder}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`Model` LIKE '%{$mfinder}%'"; // use the model as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `id`"; // order by id $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); $size = 0; $cnt = 0; "</Center></td>"; echo "<tr>"; echo "<table border='0' width '955' align=center>"; echo "</tr>"; echo "<br>"; echo "<table border='1' width='955' align=center>"; echo "<tr>"; echo "<td><b>Make</b></td>"; echo "<td><b>Model</b></td>"; echo "<td><b>Detail</b></td>"; echo "<td><b>Capacity</b></td>"; echo "<td><b>Year</b></td>"; echo "<td><b>Vented/Solid</b></td>"; echo "<td><b>Diameter</b></td>"; echo "<td><b>Thickness</b></td>"; echo "<td><b>Disk Bore</b></td>"; echo "<td><b>Studs</b></td>"; echo "<td><b>Part Number</b></td>"; echo "<td><b>Price</b></td>"; echo "</tr>"; while ($row1 = mysql_fetch_array($searchResult)) { echo "<tr>"; echo "<td>".$row1['Make']."</td>"; echo "<td>".$row1['Model']."</td>"; echo "<td>".$row1['Detail']."</td>"; echo "<td>".$row1['Capacity']."</td>"; echo "<td>".$row1['Year']."</td>"; echo "<td>".$row1['Vs']."</td>"; echo "<td>".$row1['Dia']."</td>"; echo "<td>".$row1['Thick']."</td>"; echo "<td>".$row1['Bore']."</td>"; echo "<td>".$row1['Studs']."</td>"; echo "<td>".$row1['Part']."</td>"; echo "<td>".$row1['Price']."</td>"; } $cnt++; echo "</tr>"; echo "</table>"; echo "<br><br><br><br><br>"; } function removeEmpty($var) { return (!empty($var)); } session_destroy(); ?> </p>
-
You have no idea how many times i've desk checked that piece of code Thank you!
-
So basically the last 2 months i've been teaching myself PHP, the following page used to have its own table for a make of car, (I.e. 1 for Ford, 1 for Vauxhall etc) but i recently changed it to 1 Master table, where each edit page drags through the make (Ford drags Ford from "parts" in this case) Since doing this, i cant seem to get entries to update! I click update, the top fields are filled, and then i change something and hit submit and the address changes to ID=xxxx (xxxx is the id number that appears), but nothing updates it just seems to refresh the listing! Can anyone point out what im missing? <?php require_once("Connections/connection.php"); // database connection session_start(); include("includes/security.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style3 {font-size: 9} --> </style> </head> <?php error_reporting (E_ALL ^ E_NOTICE); ?> <!-- TemplateBeginEditable name="EditRegion1" --><?php $car = chrysler; $carmakes = chrysler; ?><!-- TemplateEndEditable --> <?php error_reporting (E_ALL ^ E_NOTICE); ///////////////////////////////////////////////// variables $Product = $_POST['Product']; $Make = $_POST['Make']; $Model = $_POST['Model']; $Year = $_POST['Year']; $Fitment = $_POST['Fitment']; $Part = $_POST['Part']; $Location = $_POST['Location']; $orgPrice = $_POST['OriginalPrice']; $Price = $_POST['Price']; $Submit = $_POST['Submit']; $del = $_GET['del']; $upd = $_GET['upd']; $update_id = $_POST['update_id']; ////////////////////////////////////// $query = sprintf("SELECT * FROM parts where ID='$upd'"); $result = @mysql_query($query); //tells the database $rowUpdate = mysql_fetch_array($result); //fetches the result ////////////////////////////////////// /////////////////////////////// The following checks if there is stuff in every field and not in the hidden update field if ($Submit && $Product && $Make && $Model && $Year && $Fitment && $Part && $Location && $orgPrice && $Price && ! $update_id){ /////////////////////////////////////////////////////// this inserts it $query = sprintf("INSERT INTO parts (Product, Make, Model, Year, Fitment, Part, Location, OriginalPrice, Price) values ('$Product', '$Make', '$Model', '$Year', '$Fitment', '$Part', '$Location', '$orgPrice', '$Price')"); mysql_query($query)or die (mysql_error()); }elseif($Submit && $update_id){ ////////////////Otherwise ////////////////////////////////////////// UPDATE $query = sprintf("UPDATE parts set Product='$Product', Make='$Make', Model='$Model', Year='$Year', Fitment='$Fitment', Part='$Part', Location='$Location', OriginalPrice='$orgPrice', Price='$Price', where ID='$update_id'"); $result = @mysql_query($query); } ///delete a record if if ($del){ //////////////////////////////////////////////// This is the code for deleting a line $query = sprintf("DELETE FROM parts where ID='$del'"); mysql_query($query)or die (mysql_error()); } ////////////////////////////////////// Then show it $query = sprintf("SELECT * FROM parts WHERE make='$car'"); //selects all data from the database $result = @mysql_query($query); //tells the database $row = mysql_fetch_array($result); //fetches the result $query = " ORDER BY `Model`"; ///////////////////////////////////// ?> <body> <p><br /> <a href="../welcome.php">Back to Makes</a> </p> <table width="891" border="0"> </table> <!-- TemplateBeginEditable name="EditRegion2" --><!-- TemplateEndEditable --> <table width="200" border="0"> <tr> <td width="996"><form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <p> </p> <table width="103%" height="104" border="1"> <tr> <td width="13%"><div align="center">Product</div></td> <td width="7%"><div align="center">Make</div></td> <td width="11%"><div align="center">Model</div></td> <td width="10%"><div align="center">Year</div></td> <td width="15%"><div align="center">Fitment</div></td> <td width="6%"><div align="center">Part</div></td> <td width="10%"><div align="center">Location</div></td> <td width="10%"><div align="center">OriginalPrice</div></td> <td width="7%"><div align="center">Price</div></td> </tr> <tr> <td><span class="style3"> <label> <input name="Product" type="text" id="Product" value="<?php echo $rowUpdate['Product']; ?>" size="20" /> </label> </span> <label></label></td> <td><label> <input name="Make" type="text" id="Make" value="<?php echo $rowUpdate['Make']; ?>" size="10" /> </label></td> <td><label> <input name="Model" type="text" id="Model" value="<?php echo $rowUpdate['Model']; ?>" size="18" /> </label></td> <td><label> <input name="Year" type="text" id="Year" value="<?php echo $rowUpdate['Year']; ?>" size="15" /> </label></td> <td><label> <input name="Fitment" type="text" id="Fitment" value="<?php echo $rowUpdate['Fitment']; ?>" /> </label></td> <td><label> <input name="Part" type="text" id="Part" value="<?php echo $rowUpdate['Part']; ?>" size="12" /> </label></td> <td><label> <input name="Location" type="text" id="Location" value="<?php echo $rowUpdate['Location']; ?>" size="15" /> </label></td> <td><label> <input name="OriginalPrice" type="text" id="OriginalPrice" value="<?php echo $rowUpdate['OriginalPrice']; ?>" size="15" /> </label></td> <td><label> <input name="Price" type="text" id="Price" value="<?php echo $rowUpdate['Price']; ?>" size="10" /> </label></td> </tr> <tr> <td colspan="10"><label> </label> <div align="center"> <label> <input type="reset" name="Reset" id="Reset" value="Reset" /> </label> <input type="submit" name="Submit" id="Submit" value="Submit" /> <input name="Submit" type="hidden" id="Submit" value="1" /> <input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['ID']; ?>" /> </div></td> </tr> </table> <br /> <br /> </form></td> </tr> </table> <table width="1194" height="76" border="1"> <tr> <td width="56">Edit</td> <td width="40" height="42"><div align="center">ID</div></td> <td width="113"><div align="center">Product</div></td> <td width="111"><div align="center">Make</div></td> <td width="116"><div align="center">Model</div></td> <td width="89"><div align="center">Year</div></td> <td width="101"><div align="center">Fitment</div></td> <td width="82"><div align="center">Part</div></td> <td width="67"><div align="center">Location</div></td> <td width="87"><div align="center">OriginalPrice</div></td> <td width="31"><div align="center">Price</div></td> <div align="center"></div></td> <td width="57"> </td> </tr> <?php do { ?> <tr> <td><label> </label> <div align="center"> <input type="button" name="Update" id="Update" value="Update" onclick="document.location.href='<?php echo $carmakes?>_staff.php?upd=<?php echo $row['ID'] ?>'" /> </div></td> <td height="25"><?php echo $row['ID']; ?></td> <td><?php echo $row['Product']; ?></td> <td><?php echo $row['Make']; ?></td> <td><?php echo $row['Model']; ?></td> <td><?php echo $row['Year']; ?></td> <td><?php echo $row['Fitment']; ?></td> <td><?php echo $row['Part']; ?></td> <td><?php echo $row['Location']; ?></td> <td><?php echo $row['OriginalPrice']; ?></td> <td><?php echo $row['Price']; ?></td> <td><input type="button" name="Button" id="Button" value="Delete" onclick="document.location.href='<?php echo $carmakes?>_staff.php?del=<?php echo $row['ID'] ?>'" /> </td> </tr> <?php }while ($row = mysql_fetch_array($result)); ?> </table> <p> </p> <p> </p> <p> </p> <p></p> <p> <label></label></p> </body> </html>
-
Hi i've created a MySql table which consists of about 10 columns, and im about to start populating it with around 15,000+ entries.. The contents of this table are fetched by PHP and different results from the table are displayed on different pages of my site, depending on a certain branding (E.g. a page for bosch, a page for sony, a page for sanyo, but all coming from the same table, which will use a search feature to fetch the relevant information into each page) As its a website, obviously likely that all pages (About 40 brands) would be looked at at the same time by many many people Is this going to be very slow? If so is it going to be much slower than if i split the tables up into 40 different brands?
-
So if i have an array that varies in how many sets of results there are, how would i go about putting it into a table of multiple rows, with column headings? Below is in my current code, and this just gives the results in a list , trying to put it into table of 4 columns, with as many rows of data as required, depending on the size of the array: <?php else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['Column1']}<br />{$row['Column2']}<br />{$row['Column3']}<br />{$row['Column4']}<br />{$row['Column5']}<br /><br />"; $i++; } } function removeEmpty($var) { return (!empty($var)); } ?> Tried to keep it short and to the point, thanks!
-
I've recently been building a site, and have followed the SQL tutorial on searching databases thats on the phpfreaks site. I've tailored it to the needs of the site im designing, and am trying to get the search function to put the results into a table. The example shown below works, and is basically an adaption of the Tutorial on the site.. $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($roww = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$roww['Make']}<br />{$roww['Model']}<br />{$roww['Part']}<br />{$roww['Product']}<br />{$roww['Year']}<br />{$roww['Fitment']}<br />{$roww['Part']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search for your model of car (e.g. Escort): <input type="text" name="search" value="<?php echo isset($searchTerms)?$searchTerms:''; ?>" /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> however trying to put the data that appears from a successful search straight into a table on the same page is proving a task. Im trying to put it into a table of 9 columns, each with a seperate heading (Product, Make, Model, Year, Fitment, Part, Location, OriginalPrice and Price) and the corresponding results shown directly below. So, if there is 3 matches on the search, obviously it would show a row of 9 columns, followed by 3 rows with the search data in... so far this is what i have, giving me an error on line 55: $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} gave no results. Try shortening the Model (e.g. Escort instead of Escort RS Turbo)"; }else { $results = array(); // the result array $i = 1; while ($roww = mysql_fetch_assoc($searchResult)) { $results[] = {$i}: {$roww ?> <table width="200" border="1"> <tr> <td>Product</td> <td>Make</td> <td>Model</td> <td>Year</td> <td>Fitment</td> <td>Part</td> <td>OriginalPrice</td> <td>Price</td> <td>ToOrder</td> </tr> <tr> <td><?Php {$roww['Product']}?></td> <td><?Php {$roww['Make']} ?></td> <td><?Php {$roww['Model']} ?></td> <td><?Php {$roww['Year']} ?></td> <td><?Php {$roww['Fitment']} ?></td> <td><?Php {$roww['Part']} ?></td> <td><?Php {$roww['OriginalPrice']} ?></td> <td><?Php {$roww['Price']} ?></td> <td><?Php {$roww['ToOrder']} ?></td> </tr> </table> <?Php $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style3 {font-size: 9} --> #error { color: red; } </style> </head> <body> <br /> <br /> <?php echo (count($error) > 0)?"The following occured:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search for your model of car (e.g. Escort): <input type="text" name="search" value="<?php echo isset($searchTerms)?$searchTerms:''; ?>" /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> <br /> <p> <label></label></p> <table width="950" height="76" border="1"> <tr> <td width="113" height="42"><div align="center">Product</div></td> <td width="111"><div align="center">Make</div></td> <td width="116"><div align="center">Model</div></td> <td width="89"><div align="center">Year</div></td> <td width="101"><div align="center">Fitment</div></td> <td width="82"><div align="center">Part</div></td> <td width="87"><div align="center">OriginalPrice</div></td> <td width="41"><div align="center">Price</div></td> <td width="152"><div align="center">To Order</div> <div align="center"></div></td> </tr> <?php do { ?> <tr> <td height="25"><?php echo $row['Product']; ?></td> <td><?php echo $row['Make']; ?></td> <td><?php echo $row['Model']; ?></td> <td><?php echo $row['Year']; ?></td> <td><?php echo $row['Fitment']; ?></td> <td><?php echo $row['Part']; ?></td> <td><?php echo $row['OriginalPrice']; ?></td> <td><?php echo $row['Price']; ?></td> <td><?php echo $row['ToOrder']; ?></td> </tr> <?php }while ($row = mysql_fetch_array($result)); ?> </table> </body> </html> Any help would be greatly appreciated!
-
I tried with the backticks and was unsuccessful, however changed the column name "order" and this appears to have fixed the problem, after my many hours of trawling through code before... The tutorial never mentioned a problem with naming the column headings, when it said syntax i simply assumed id missed a comma or a bracket somewhere, not the words i was using. Good to know! Next is creating a PHP search box, i've seen a tutorial on the forums here so i think ill go away and have a read of that and get some more done... Many thanks!