PHP - Pagination Populating Prev And Next
Hi,
I'm trying to populate the previous and next links with an id from mysql. The code below works but also displays ids that do not exist in the database. I want the code to only show me the rows that exist not the ones that do not exist. For example, at this time I have 5 rows. The ids of the rows are 1, 2, 3, 4, 6 when I get to say, id 6 and click on next it displays id 7 instead of going back to 1 or greying out next - meaning there's no more to view. Can someone help? <?php include('connection.php'); if(isset($_GET['id'])){ $start = $_GET['id']; }else{ $start = 0; } $sql = mysql_num_rows(mysql_query("SELECT * FROM thetable")); $result = mysqli_query($con,$sql); $rows = mysql_fetch_array($result); echo $rows['thetable']; if($start == 0){ echo "Previous «"; }else{ echo "<a href=\"./thepage.php?id=" . ($start - 1) . "\">« Previous </a>"; } if($start == $sql-1){ echo "Next »"; }else{ echo "<a href=\"./thepage.php?id=" . ($start + 1) . "\">Next »</a>"; } ?> <?php // End while loop. mysqli_close($con); ?> Similar TutorialsI was wondering if someone could give me the code for a next and prev button at the bottom of my search page...here is my code for the search page now however when I click next it says please fill in all search fields... Code: [Select] <?php // Get the search variable from URL $var = $_GET['search'] ; $searchtype = $_GET['searchtype']; $isbn = "ISBN"; $school = "School"; $title = "Title"; $subject = "Subject"; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database $connect = mysql_connect("db","username","pass") or die("Not connected"); //specify database mysql_select_db("db") or die("could not log in"); if ($searchtype == ($title)) { // Build SQL Query $query = "select * from boox where name like \"%$trimmed%\" order by name"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($school)) { // Build SQL Query $query = "select * from boox where school like \"%$trimmed%\" order by school"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($isbn)) { // Build SQL Query $query = "select * from boox where isbn like \"%$trimmed%\" order by isbn"; // EDIT HERE and specify your table and field names for the SQL query echo "isbn"; } elseif ($searchtype == ($subject)) { // Build SQL Query $query = "select * from boox where subject like \"%$trimmed%\" order by subject"; // EDIT HERE and specify your table and field names for the SQL query } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . "" in "" . $searchtype ."" </p>"; // begin to show results set echo "Results "; $count = 1 + $s ; if ($searchtype = $title) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["name"]; echo "$count. $title   </br><table width='297' border='1' align='center'> <tr> <td width='152'>Book Title:</td> <td width='129'>$row[name]</td> </tr> <tr> <td>Author:</td> <td>$row[author]</td> </tr> <tr> <td>ISBN#</td> <td>$row[isbn]</td> </tr> <tr> <td>Date Posted:</td> <td>$row[date]</td> </tr> <tr> <td>Posted By:</td> <td><a href='backpack.php?usr=$row[username]'>$row[username]</a></td> </tr> <tr> <td>School:</td> <td>$row[school]</td> </tr> </table></br>"; $count++ ; } } elseif ($searchtype = $school) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["school"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $subject) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["subject"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $isbn) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["isbn"]; echo "$count. $title" ; $count++ ; } } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> This is the code I have now however when you click next to view more results it says please enter a search..., (there is more code above this however I thought that the problem would be within the code provided.) $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> Could anyone point me in the correct direction of how to go about excluding results from a drown down menu, Basically i'm calling everyone who's a contact to the user in the code below, id like to remove contacts who already have a bank account with the user, So basically its something along the lines of if the player_id is already in the table bank_accounts as PlayersID, then its excluded, Hope this makes sense and any help would be great, Thanks Code: [Select] <select name="contact1" class="maintablepstats" id="contact1"> <option value=""></option> <?php $sql = "SELECT player_id, contact_id, name, is_active FROM contacts as c JOIN players as p ON c.contact_id = p.id WHERE c.player_id = $playerID AND is_active = 1 ORDER BY name ASC"; $que = mysql_query($sql) or die(mysql_error()); while($list = mysql_fetch_array($que)) { ?> <option value="<?php echo $list['contact_id'] ?>"><?php echo $list['name'] ?></option> <?php } ?> </select> <?php $con=mysql_connect("localhost","root",""); if(!$con) { die('could not connect' .mysql_error()); } mysql_select_db("hrc_fault",$con); $query = "SELECT * " . "FROM fault_book"; $result = mysql_query($query, $con) or die(mysql_error()); $num_movies = mysql_num_rows($result); $registered_comp=<<<EOD <h2><center>Registered Fault HRC</center></h2> <table width="70%" border="1" cellpadding="2" cellspacing="2" align="center"> <tr> <th>Job Cd No</th> <th>Date</th> <th>Section</th> <th>Item Description</th> <th>Item Sl.No</th> <th>Fault</th> </tr> EOD; $fault_details = ''; while ($row = mysql_fetch_array($result)) { $jc_no = $row['jc_no']; $date = $row['date']; $section = $row['section']; $itm_des = $row['itm_des']; $itm_slno = $row['itm_slno']; $fault_brf = $row['fault_brf']; $fault_details .=<<<RAM <tr> <td>$jc_no</td> <td>$date</td> <td>$section</td> <td>$itm_des</td> <td>$itm_slno</td> <td>$fault_brf</td> </tr> RAM; } $movie_footer ="</table>"; $movie =<<<MOVIE $jc_no $date $section $itm_des $itm_slno $fault_brf MOVIE; echo "There are $num_movies complains in our database"; echo $movie; ?> I m using above code but it only display the last record please debug the code I'm trying to retrieve data from my DB and have it populate the dropdown values inside a form: echo "<option value='0.00' " . ($array['roastturkey'] == '0.00' ? 'selected="selected"' : '') . ">0</option>";echo "<option value='1.00' " . ($array['roastturkey'] == '1.00' ? 'selected="selected"' : '') . ">1</option>";echo "<option value='2.00'> " . ($array['roastturkey'] == '2.00' ? 'selected="selected"' : '') . ">2</option>";echo "<option value='3.00'> " . ($array['roastturkey'] == '3.00' ? 'selected="selected"' : '') . ">3</option>";echo "<option value='4.00'> " . ($array['roastturkey'] == '4.00' ? 'selected="selected"' : '') . ">4</option>";echo "<option value='5.00'> " . ($array['roastturkey'] == '5.00' ? 'selected="selected"' : '') . ">5</option>";echo "<option value='6.00'> " . ($array['roastturkey'] == '6.00' ? 'selected="selected"' : '') . ">6</option>";echo "<option value='7.00'> " . ($array['roastturkey'] == '7.00' ? 'selected="selected"' : '') . ">7</option>";echo "<option value='8.00'> " . ($array['roastturkey'] == '8.00' ? 'selected="selected"' : '') . ">8</option>";echo "<option value='9.00'> " . ($array['roastturkey'] == '9.00' ? 'selected="selected"' : '') . ">9</option>";echo "<option value='10.00'> " . ($array['roastturkey'] == '10.00' ? 'selected="selected I'm using this code, but cannot get the data that's inside the DB to populate the dropdown value. I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded. If I don't change it to the previous info it will update the database with the default option rather then the actual option. hi, I have a form that has 2 lists, first one has the months from Jan to Dec which i am done with, for the second list i want to have years from current year for other say 5 years. Example, we are in 2020 so i should have the list populate 2020,2021,2022,2023,2024 and next year it should show 2021-2025, how to do that. Here is what i have as HTML: <html> <head> <link rel="stylesheet" type="text/css" href="reportstyle.css"> </head> <body> <div class="form-wrapper"> <form action="reportanalysis.php" method="post"> <div class="form-item"> <h4>Select a month:</h4> <select id="months" name="months" required="required"> <option selected="selected" value="chose">Choose one option...</option> <option value="jan">Jan - 01</option> <option value="feb">Feb - 02</option> <option value="mar">Mar - 03</option> <option value="apr">Apr - 04</option> <option value="may">May - 05</option> <option value="jun">Jun - 06</option> <option value="jul">Jul - 07</option> <option value="aug">Aug - 08</option> <option value="sep">Sep - 09</option> <option value="oct">Oct - 10</option> <option value="nov">Nov - 11</option> <option value="dec">Dec - 12</option> </select> </div> <div class="form-item"> <h4>Select a year:</h4> <select id="years" name="years" required="required"> <option selected="selected" value="chose">Choose one option...</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> </select> </div> <div class="button-panel"> <center><button type="submit" name="reporting" class="buttonstyle">Generate Graph Report</button></center> </div> <div class="reminder"> <p><a href="home.php">Return to Main Menu</a> </div> </form> </div> </body> </html> Edited April 3, 2020 by ramiwahdan typo error I need to fill an array dynamically with all the data in the users table. Any help will be appreciated, thanks! Hello, I'm trying to populate a dropdown box in a RSForm using this code: //<code> $db = JFactory::getDbo(); $db->setQuery("SELECT Bruel_ID FROM mpctz_rsform_bruels"); return $db->loadObjectList(); //</code>However, it displays nothing in the box and some code outside of it (see attached file). Can anyone help? Thanks, Dani Attached Files APNAE.jpg 16.92KB 0 downloads I am trying to figure out how to display member records after selecting it from the box. I've got the dropdown box working which retrieves the members name but cannot figure out how to populate that members details on the same page? I'm using php/mysql and although I want to display the records I also want a user to update that record aswell, creating it for administrators to update accounts? Any help would be appreciated I've researched that ajax or javascript might be helpful but not totally familiar with them. Hi!! the question look simple at his base because I will receive TONS of answer saying ... " hey men use javascript OR ajax " but I don't want to use these... I want to populate the second dropdown menu dynamicly with PHP code. and sql query. why?? because I have over 43000 possibility and doing a script manually is impossible. the database is changing every hour. this is the code of my working page. the form NOTE: i REMOVE ALL DB CONNECTION FOR SECURITY PURPOSE. THANKS FOR YOUR UNDERTANDING. <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> </head> <body > <img src="http://www.scale24-25.com/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="326,13,330,53,98,54,90,92,670,99,668,54,889,51,886,5" href="http://www.scale-auto-style.com" alt="" /> </map> <?php if (isset($_POST['todo']) && $_POST['todo'] == "search") { $todo=$_POST['todo']; $manufacturer_reel=$_POST['manufacturer_reel']; $query="select * from kit where "; ////////// Including manufacturer_reel field search //// if(strlen($manufacturer_reel) > 0 ){ $query.= " manufacturer_reel='$manufacturer_reel' and "; } //// End of class field search /////////// $query=substr($query,0,(strLen($query)-4)); echo $query; echo "<br><br>"; $nt=mysql_query($query); echo mysql_error(); // End if form submitted }else{ echo "<form method=post action='search-keyword.php?go'><input type=hidden name=todo value=search>"; ?> <table width="960" border="0"> <tr> <td colspan="3"><p align="center"></td> </tr> <tr> <td><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right">Echelle du modele</div></td> <td align="center"> <?php // strat of drop down /// $q=mysql_query("SELECT DISTINCT scale FROM kit ORDER BY scale"); echo '<select name="scale"><option value="scale">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['scale']; echo '<option>'.$thing.'</option>'; } echo "</select>"; echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Scale of model</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td><div align="right">Nom du manufacturier automobile</div></td> <td align="center"><?php // strat of drop down /// $q=mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel"); echo '<select name="manufacturer_reel"><option value="reel manufacturer">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['manufacturer_reel']; echo '<option>'.$thing.'</option>'; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; // end of drop down /// ?></td> <td><div align="left">Name Of vehicule manufacturer</div></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right"></div></td> </tr> <tr> <td><div align="right">Nom du manufacturier de modele reduit</div></td> <td align="center"><?php // start of drop down /// $q=mysql_query("SELECT DISTINCT manufacturer_kit FROM kit ORDER BY manufacturer_kit"); echo '<select name="manufacturer_kit"><option value="kit manufacturer">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['manufacturer_kit']; echo '<option>'.$thing.'</option>'; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Name Of kit manufacturer</div></td> </tr> <tr> <td><div align="right"></div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right">Annee de fabrication du Vehicule</div></td> <td align="center"><?php // strat of drop down /// $q=mysql_query("SELECT DISTINCT year_prod_reel FROM kit ORDER BY year_prod_reel"); echo '<select name="year_prod_reel"><option value="vehicules year manufactured">Please Choose an Option</option>'; while($row = mysql_fetch_array($q)) { $thing = $row['year_prod_reel']; echo '<option>'.$thing.'</option>'; } echo "</select>"; // end of drop down /// echo " <br> \n"; echo " <br> \n"; ?></td> <td><div align="left">Year of production of the vehicule</div></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td><div align="right"><strong></strong></div></td> <td align="center"> <?php echo " <br><input type=submit value=Search name='name' action='search-keyword.php?go' > </form> "; } ?> <td><div align="left"><strong></strong></div></td> </body> </html> AND THE PAGE RESULT <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> </head> <body > <p align="center"><img src="http://www.scale24-25.com/catalog/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" /> <area shape="poly" coords="325,11,329,51,97,52,89,90,669,97,667,52,888,49,885,3" href="http://www.scale-auto-style.com" alt="" /> </map></p> <table width="920" border="0"> <tr> <td width="359"><p class="style5">You will find some TBC. TBC is for "To Be Confirmed". If somebody know the missing information ( TBC ) it will be appreciate to send it to me at this mail: <a href="mailto:info@hobby-shop.qc.ca">info@hobby-shop.qc.ca</a> <br /> <br /> thanks in advance for your help</p> </td> <td width="161"> </td> <td width="386"> <div align="right"> <p>This logo <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50'/> mean that you can download a PDF file. To read it you need minimum Acrobat reader and you can download it <a href="http://get.adobe.com/reader/">here</a></p> <p>Some link will return a TBC. Sorry for any inconveniant. as soon as we will receive or do the PDF it will be updated.</p> </div></td> </tr> </table> <br> <?php if (isset($_POST['todo']) && $_POST['todo'] == "search") { $todo=$_POST['todo']; $name=$_POST['manufacturer_reel']; $name1=$_POST['manufacturer_kit']; $name2=$_POST['year_prod_reel']; $name3=$_POST['scale']; //-query the database table for the post field $sql="SELECT kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, scale, engine_detail, year_prod_kit, year_prod_reel, image_id, image_id1, image_id2 FROM kit "; $sqlOperand="WHERE"; if ($name != "reel manufacturer") { $sql = $sql . $sqlOperand . " manufacturer_reel LIKE '%" . $name ."%' "; $sqlOperand = " AND "; } if ($name1 != "kit manufacturer") { $sql = $sql . $sqlOperand . " manufacturer_kit LIKE '%" . $name1 ."%' "; $sqlOperand = " AND "; } if ($name2 != "vehicules year manufactured") { $sql = $sql . $sqlOperand . " year_prod_reel LIKE '%" . $name2 ."%' "; $sqlOperand = " AND "; } if ($name3 != "scale") { $sql = $sql . $sqlOperand . " scale LIKE '%" . $name3 ."%' "; $sqlOperand = " AND "; } if ($sqlOperand == "WHERE") { echo "<p>Please enter a search query</p>"; } else { // echo '<img src="web-design/sorry.jpg" alt="sorry">'; // echo "Sorry nothing match your selection / Desolle rien ne correspond a votre selection"; // echo "run sql: <BR> $sql <BR> and display results"; } //-run the query against the mysql query function $result=mysql_query($sql); //-make the header of the table echo " <table align=center width=\"1340\" border=\"\">\n"; echo " <tr>\n"; echo" <td nowrap align=center width='95'> kit manufacturer \n"; echo" <td nowrap align=center width='55'> scale \n"; echo" <td nowrap align=center width='90'> kit number \n"; echo" <td nowrap align=center width='290'> kit name \n"; echo" <td nowrap align=center width='400'> description \n"; echo" <td nowrap align=center width='125'> vehicule year \n"; echo" <td nowrap align=center width='80'> complete engine detail\n"; echo" <td nowrap align=center width='80'> Select Picture to get bigger\n"; echo" <td nowrap align=center width='75'> instruction sheet\n"; echo" <td nowrap align=center width='75'> box contain\n"; echo " <tr>\n"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $description =$row['description']; $manufacturer_kit=$row['manufacturer_kit']; $scale=$row['scale']; $manufacturer_reel=$row['manufacturer_reel']; $kit_id=$row['kit_id']; $kit_number=$row['kit_number']; $kit_name=$row['kit_name']; $engine_detail=$row['engine_detail']; $year_prod_reel=$row['year_prod_reel']; $image_id=$row['image_id']; $image_id1=$row['image_id1']; $image_id2=$row['image_id2']; //-create table of item during he while loop echo " <table align=center width=\"1340\" border=\"\">\n"; echo" <td nowrap align=center width='95'> $manufacturer_kit \n"; echo" <td nowrap align=center width='55'> $scale \n"; echo" <td nowrap align=center width='90'> $kit_number \n"; echo" <td nowrap align=center width='290'> $kit_name \n"; echo" <td nowrap width='400'> $description \n"; echo" <td nowrap align=center width='125'> $year_prod_reel \n"; echo" <td nowrap align=center width='80'> $engine_detail \n"; echo" <td nowrap width='80'> <a href=".$image_id."> <img src='".$image_id."' width='75' height='50' border='0'/>"; echo" <td nowrap width='75'> <a href= ".$image_id1."> <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>"; echo" <td nowrap width='75'> <a href=".$image_id2."> <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>"; echo " </tr>\n"; echo " </table>\n"; echo " </tr>\n"; echo " </table>\n"; } } else{ echo "<p>Please enter a search query</p>"; } ?> </body> </html> YOU CAN SEE IN THE FORM i HAVE A DROP DOWN MENU CALL Name Of vehicule manufacturer .. IN VACT THIS IS THE REAL CAR MANUFACTURER EX: TOYOTA, gmc ETC.. WHEN THE USER WILL SELECT ONE OF THESE AN OTHER DROPDOWN ( NOT SHOWN ) WILL DISPLAY EVERY MODEL FOUND IN THE DATABASE IN RELATION WITH THE MANUFACTURE. IN FACT IT'S LOCATED IN THE TABLE. SO HOW I CAN GET THIS RELATION?? YOURS SEBASTIEN trying to get a drop-down menu (in a form) to work that needs to get populated from a table table called : CarCategory in this table are 2 columns called CarCategoryID (unique number from 1-18) CarCategoryDesc (actual name of category.. e.g. 'convertible') link : http://98.131.37.90/postPart.php I'm a total novice.. and can't figure out why the first is not working and the second (country) is working code : <!--NOT WORKING ... why not ?? should show drop down menu--> <label> <div align="center"> <select name="carcategory" id="CarCategory" class="validate[required]" style="width: 200px;"> <option value="">Select Car Category from list...</option> <?php while($obj_queryCarCategory = mysql_fetch_object($result_queryCarCategory)) { ?> <option value="<?php echo $obj_queryCarCategory->CarCategoryID;?>" <?php if($obj_queryCarCategory->CarCategoryID == $UserCountry) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarCategory->CarCategoryDesc;?></option> <?php } ?> </select> </div> </label> <!-- working ! --> <label> <div align="center"> <select name="country" id="Country" class="validate[required]" style="width: 200px;"> <option value="">Select...</option> <?php while($obj_queryCountry = mysql_fetch_object($result_queryCountry)) { ?> <option value="<?php echo $obj_queryCountry->CountryID;?>" <?php if($obj_queryCountry->CountryID == $UserCountry) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCountry->CountryName;?></option> <?php } ?> </select> </div> </label> How would I force a certain table format and then populate it with the SQL results in their respective columns and rows? i.e. Code: [Select] +------------------+----------+----------+----------+ | | Col 1 | Col 2 | Col 3 | +-------------------+----------+----------+----------+ | row 1 lab data | 16777216 | | 573 | +-------------------+----------+----------+----------+ | row 2 lab data | 23454235 | 87247247 | 65743 | +-------------------+----------+----------+----------+ | row 3 lab data | 16777216 | 47832364 | | +-------------------+----------+----------+----------+ Currently I'm just using a while loop to populate it horizontally, but that doesn't work for row 1. Code: [Select] <?PHP while($row = mysql_fetch_array($result) { ?> blah blah blah html here <?PHP echo $row[0]; ?> more html <?PHP echo $row[1]; ?> and so forth <?PHP } ?> It ends up producing this: Code: [Select] +------------------+----------+----------+----------+ | | Col 1 | Col 2 | Col 3 | +-------------------+----------+----------+----------+ | row 1 lab data | 16777216 | 573 | | +-------------------+----------+----------+----------+ | row 2 lab data | 23454235 | 87247247 | 65743 | +-------------------+----------+----------+----------+ | row 3 lab data | 16777216 | 47832364 | | +-------------------+----------+----------+----------+ Hi, Can someone help me with the following problem... I am populating a html table with results from a mysql query. These results populate the 1st of four columns. The second column is a "RAG STATUS" dropdown menu - so GREEN/AMBER/RED. When this is selected I want it to change the colour of the corresponding row it is on. I have had a play around but can only get it to change the colour of the first row, no matter which dropdown menu I change. Code is below. If anything is not clear please let me know. Any help appreciated Code: [Select] <?php include ("commonTop.php"); include("dbvariables.php"); include("functions.php"); ?> <script type="text/javascript"> function changeBGCol(status) { document.getElementById("colour").bgColor=status; } </script> <?php $Checkout_ID = 2; $result = mysql_query( "SELECT Task FROM Task T, Checkout C Where T.Checkout_ID = C.Checkout_ID and C.Checkout_ID= $Checkout_ID" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); echo "This will be sent to the following recepients $num_rows records.<P>"; echo "<table width=70% border=3>\n"; echo "<tr><th>Check</th><th>STATUS</th><th>JIRA</th><th>Comments</th></tr>"; while ($get_info = mysql_fetch_row($result)){ echo "<tr id=colour>\n"; foreach ($get_info as $field) echo "\t<td><font face=arial size=1/>$field</font></td>\n"; echo "\t<td><select name='Status'> <option value='None'>-- Choose --</option> <option onclick='changeBGCol(this.value)' value='green' >GREEN</option> <option onclick='changeBGCol(this.value)' value='orange'>AMBER</option> <option onclick='changeBGCol(this.value)' value='red'> RED</option> </select></td>"; echo "\t<td><input type='text' name='JIRA'></td>"; echo "\t<td><input type='text' name='Comments'></td>"; echo "</tr>\n"; } print "</table>\n"; ?> [code] </code> Any help on this would be greatly appreciated. I am trying to run a mysqldump from my site for my client when they want to back up. They basically will jsut click a button to run the backup. With my script below, the backup file is genrated, but there is no table data in the file. There are the headers in the file with the server IP, linux versin, etc..., but there is no data in the file. Does this look right? Thank you for helping me out. Ryan Code: [Select] ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbhost = 'localhost'; $dbuser = 'databaseuser'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'database'; mysql_select_db($dbname); $tableName = 'lots'; $backupFile1 = '/home/stuff/wwwroot/stuff/appnew/backup/'; $backupFile = $backupFile1.$dbname . date("Y-m-d-H-i-s") . '.gz'; $command = "mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname | gzip > $backupFile"; system($command); $result = mysql_query($command); Basically, I have a database table called 'users' and I would like to populate a drop down box with these values of 'users'. How?? - to call upon the values is this: 'upduser2' Right now, all I am using is a text box, in where you have to type in the users name manually (this is so an admin can change variables and settings according to that current user). This is what I am using so far: <h3>Update User Level</h3> <? echo $form->error("upduser"); ?> <table> <form action="adminprocess.php" method="post"> <tr> <td> Username:<br /> <input type="text" name="upduser" maxlength="30" value="<? echo $form->value("upduser"); ?>" /></td> <td> Level:<br /> <select name="updlevel"> <option value="1">1 </option> //example settings <option value="9">9 </option> </select></td> <td><br /> <input type="hidden" name="subupdlevel" value="1" /> <input type="submit" value="Update Level" /></td> </tr> </form> </table></td> </tr> Much help would be appreciated. Ok, so i got this website project dropped in my lap, and I'm stuck not really having done much php coding ever. I have a database which is linked already, and it was working when pulling data from a specific table. The problem arose when I was asked to make it work with other tables. I have a table with the table names in it, and the drop down field to select the table populates. The next field is a multiple select field that is supposed to populate report dates from the previously selected table, and then finally the last multiple select field is supposed to populate with names that match the dates selected from the previous field. The last one I can live without, as the existing code takes into account if the name selected doesn't exist in the table with the selected date, but at the moment the date field just comes up blank. Any help would be greatly appreciated. Hi I making some forms that write to mysql database, Im now in the process of making the update form so the user can update there details on the form, I want it to populate the form with existing data but its not doing it at all. Thanks in advance
Attached Files
delete.php 210bytes
2 downloads
modify.php 4.03KB
4 downloads
index.php 473bytes
3 downloads Hi people,
I'm new to PHP, and I'm having some real difficulties with trying to re-populate a radio button selection on a form.
Basically, I'm working on a WordPress plugin which uses custom fields to create a Bet custom post type.
I need to have my form submit the user input, then re-populate it so that if the user wants to edit and update the Bet data, they don't have to fill in the whole form details again, they can just edit what they need to, and update (re-submit) the form.
I've managed to get all of the form elements re-populating, apart from a radio button. I've been trawling round the internet for most of yesterday evening and this morning, trying different things, but nothing I've found works for me.
I'd really appreciate some help if anyone knows how to do this.
Here's my code so far (non working)
<?php Alright so I created a MySQL database that has 5 tables each named a brand of a dirt bike. In each table their are 2 fields, one INDEX_ID and MODELS. Under that for rows I have every model bike named. A quick question before I get onto what I want to do: Can data be added underneath the rows? For example, users will be able to submit information about each bike model. If each bike model is a row, can there be a category past that row or do I need to make each field a model name and just have a ton of fields and have the rows be the information users submit. To make it easier to understand I'll post the SQL code for the brand Honda: CREATE TABLE `Honda` ( `INDEX_ID` int(3) NOT NULL auto_increment, `MODELS` varchar(20) collate latin1_general_ci NOT NULL, PRIMARY KEY (`INDEX_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=23 ; -- -- Dumping data for table `Honda` -- INSERT INTO `Honda` VALUES(1, 'CR85'); INSERT INTO `Honda` VALUES(2, 'CR125'); INSERT INTO `Honda` VALUES(3, 'CR250'); INSERT INTO `Honda` VALUES(4, 'CRF100'); INSERT INTO `Honda` VALUES(5, 'CRF150'); INSERT INTO `Honda` VALUES(6, 'CRF230'); INSERT INTO `Honda` VALUES(7, 'CRF250X'); INSERT INTO `Honda` VALUES(8, 'CRF250R'); INSERT INTO `Honda` VALUES(9, 'CRF450X'); INSERT INTO `Honda` VALUES(10, 'CRF450R'); INSERT INTO `Honda` VALUES(11, 'CRF50'); INSERT INTO `Honda` VALUES(12, 'CRF70'); INSERT INTO `Honda` VALUES(13, 'CRF80'); INSERT INTO `Honda` VALUES(14, 'XR650'); INSERT INTO `Honda` VALUES(15, 'CR500'); INSERT INTO `Honda` VALUES(16, 'XR100'); INSERT INTO `Honda` VALUES(17, 'XR200'); INSERT INTO `Honda` VALUES(18, 'XR250'); INSERT INTO `Honda` VALUES(19, 'XR400'); INSERT INTO `Honda` VALUES(20, 'XR50'); INSERT INTO `Honda` VALUES(21, 'XR70'); INSERT INTO `Honda` VALUES(22, 'XR80'); Anyway I still need to figure out how to have this under a form that a user can use to select the bike they want to submit information about. A code like this perhaps?: <? $connection = mysql_connect("localhost","user","pass"); $fields = mysql_list_fields("dbname", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; ?> Thanks. Dear All, I have attached here with a schema, of MySql DB format i am refering to for the topic i need help on. I want to know what is the best way to achieve this problem / task. I have a profile table, and a category table, and a table to map profiles to category. Which allows me to define/add into the category_profile_mapping table, profile ids against a category id. Each category can have anywhere between 2 to 1,00,000 profiles mapped to it. I have another table called sms_out. hence on the site, when i select a category and submit the form value with message, i want to know what is the best way to populate sms_out with MSISDN from the table "Profile" and the message from the form. The list of MSISDN will be based on the category id selected, hence the profile id's will be available in the category_profile_mapping table. I am bad at explaining the problem, however incase you folks need more info do let me know. i shall be glad to provide the same to .. all of you guys who are willing to help me PS: I am asking this question, cuz i want to knw the best solution to achieve this, when there is entries in millions to be done at one form submit. [attachment deleted by admin] |