Jump to content


  • Posts

  • Joined

  • Last visited


Profile Information

  • Gender
    Not Telling

hal_11's Achievements


Newbie (1/5)



  1. Am also interested in figuring out a solution to this...anybody n e ideas??
  2. BUMP * ---<STUCK> i still cant figure out how to get the multiple checboxes to execute the mysql queries. Any help would be appreciated </STUCK>
  3. ok played around with it for a bit there, still no joy, it doesnt seem to be executing the query for price at all...il include the php code see if you can spot anything im missing<?> <?php // Let's add some blurb before and after the conversion specification require_once ('mysqli_connect.php');//connect to database $where = ''; if (isset($_POST['price']) && !empty($_POST['price'])) { $price = $_POST['price']; foreach($price as $p) { if (preg_match('/[0-9]\-[0-9]+/', $p)) { $p = explode('-', $p); $where .= 'price BETWEEN ' . $p[0] . ' AND ' . $p[1] . ' OR '; } else if (preg_match('/[0-9]+\+/', $p)) { $where .= 'price >= ' . str_replace('+', '', $p) . ' OR '; } } } if (!empty($where)) $where = 'WHERE ' . trim($where, ' OR '); $q = mysql_query("SELECT price FROM package " . $where); $r = @mysqli_query ($dbc, $q); //run query if ($r) { // display if ok. //Table header echo '<table style="table-layout: fixed" width="100%" border="1px"> <tr> <td align="left"><b>Supplier</b></td> <td style="word-wrap:break-word"><b>Package</b></td> <td align="left" width="40%"><b>Package Details</b></td> <td align="left" width="10%"><b>(£) Price</b></td> </td></tr> '; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr><td align="left">' . $row['supplier'] . '</td> <td align="left">' . $row['package'] . '</td> <td align="left">' . $row['pack_info'] . '</td> <td align="left">' . $row['FORMAT(p.price,2)'] . '</td></tr>'; } echo '</table>'; //mysqli_free_reult($r);// free up resources } else { // if it did not work //public message echo '<p class="error">The current record could not be retrieved at this time!</p>'; //debugging message echo '<p>' . mysqli_error($dbc) . '<br/><br/>Query: ' . $q. ' </p>'; } // end of if ($r) IF. mysqli_close($dbc);//close connection ?> Thought i had it working for a second but i mustnt be coding the query correctly....bummer
  4. Cheers, just tried it there, Seems like somethings suppose to happen, when i tick one or more boxes, screen is blank, when i submit with none selected i get the following.. Notice: Undefined index: price in C:\wamp\www\test script\myscript.php on line 13 Warning: Invalid argument supplied for foreach() in C:\wamp\www\test script\myscript.php on line 17 Any ideas? Definitley think im on the right track with this, just wont bloody work
  5. Thanks, not exactly sure how i would implement this code though Do i require an sql query in this aswell? So to start i would set out like so? HTML <form action="myscript.php" method="post"> <input type="checkbox" name="price[]" value="0">Price 0-£500 </font><br> <input type="checkbox" name="price[]" value="1"> Price £500-£1000</font><br> <input type="checkbox" name="price[]" value="2"> Price £2000+</font><br></form> PHP <?php include ('header.php'); $page_title = 'price'; require_once ('mysqli_connect.php');//connect to database $price = $_POST['price']; $range = array(); foreach($price as $p) { $range = array_merge($range, $p); } $range = array_unique($range); $x = $range[0]; $z = $range[count($range) -1]; // now $x is equal to the first number (0) // and $z is equal to the last number (1000) // now you can use MYSQLs BETWEEN operator ?>
  6. I am trying to implement a multiple checkbox function were a user can select one or more from the checkbox, and the results will be filtered through the mysql query. <form action="myscript.php" method="post"> <input type="checkbox" name="checkbox[]" value="price0">Price 0-£500 </font><br> <input type="checkbox" name="checkbox[]" value="price1"> Price £500-£1000</font><br> So i have declared the array in the html checkbox for say price and wish to combine these queries and retrieve the chosen prices from the db. Im not quite sure how to write up the php part of the code for the array..... I have individual queries written that will display individually but I really want them to be able to combine to suit the users needs.. I have inserted the code for one of my queries if that can help with were (and how) to set up the array. Thanks for the help.. require_once ('mysqli_connect.php');//connect to database //number of records $display = 10; if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined $pages = $_GET['p']; } else { //Need to determine. $q = "SELECT COUNT(price) FROM package WHERE (price BETWEEN 0 AND 499.00) "; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; if ($records > $display) {//more than 1 page $pages = ceil ($records/$display); } else { $pages = 1; } if (isset($_GET['s']) && is_numeric ($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort //default is package $sort = (isset($_GET['sort'])) ? $_GET ['sort'] : 'p'; switch ($sort) { case 'p': $order_by = 'package ASC'; break; case 's': $order_by = 'supplier ASC'; break; case 'pd': $order_by = 'pack_info ASC'; case 'pr': $order_by = 'price ASC'; break; default: $order_by ='package ASC'; $sort = 'p'; break; } //make the query. $q ="SELECT s.supplier, p.package, p.pack_info, FORMAT(p.price,2) FROM supplier AS s INNER JOIN package AS p USING (sup_id) WHERE (p.price BETWEEN 0 AND 499) ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); //run query echo '<table style="table-layout: fixed" width="100%" border="1px" cellpadding="10"> <tr> <td align="left"><b><a href="499.php?sort=s">Supplier</b></td> <td style="word-wrap:break-word"><b><a href="499.php?sort=p">Package</b></td> <td align="left" width="40%"><b><a href="499.php?sort=pd">Package Details</b></td> <td align="left" width="10%"><b><a href="499.php?sort=pr">(£) Price</b></td> </td></tr>'; $bg = '#eeeeee';//set initial background while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // switch background color. echo '<tr bgcolor="' . $bg . '"><td align="left">' . $row['supplier'] . '</td> <td align="left">' . $row['package'] . '</td> <td align="left">' . $row['pack_info'] . '</td> <td align="left">' . $row['FORMAT(p.price,2)'] . '</td></tr>'; }//end while loop echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc);//close connection
  7. yea true..i seem to have some part of it working so far..iv changed the GET url to one of my queries..e.g. price.php..this shows up whenever i click any checkbox option...Do i need to modify onclick='stuff(100); to the matching php file or am i completley missing something lol? And also if more than one is selected will that combine the queries to narrow the results? Thanks once again for all your help!
  8. Thanks, il give that a try..should i create a seperate html file for checkboxes and include the php file or to keep it all as one, as i am currently using one php file and using echo to create the tables? possibly a dumb question but thought id ask
  9. Thanks for the reply, Im not really sure how this will retrieve the information from the database through each query though ..im kind of a newb at this area of coding!...Iv provided a link to what im trying to achieve, that will explain it better than i ever could. http://www.dfs.co.uk/sofas/leather-sofas/ The dfs site filters results on the same pages but also combining each query when a checkbox is selected, i think there is some ajax involved in achieving this also..
  10. Hi all, iv been trying to compile a script that will allow users to select multiple checkboxs that will filter results from db..but to no avail. I have my data stored in mysql and have the queries saved seperatley. i.e. price = 0-500, 500-1000.etc. What im trying to achieve is to allow users to select a checkbox that will execute that particular query and also more importantly allow them to select 'multiple' checkboxes that will filter the results accordingly. I have never attempted to code this before although I am aware that it might involve arrays. If someone could give me a nudge in the right direction that would be great :-)
  • 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.