PHP - Moved: Displaying Items That Start With A Number From The Database
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=334480.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354650.0 Right now I have a link list a-z and 0-9. you click one of those links and your taken to page listing all items that start with that character. currently I'm using: Code: [Select] SELECT * FROM my_table where LEFT(`my_item`,1)='$show' ORDER BY my_title ASCall I do right now is just add a link like ?show=a and everything that starts with a is listed. Now here is my problem. I want to listen all items that start with a numeric value listed all on one page instead of being spread across 0-9. If another solution becomes available I'd be more then happy to hear you out. But does anyone know how I can change my query to only list items that start with numbers? I have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308347.0 hey guys i have this invoice im working on but my clients want's the invoice id start at a specific number?
do it put that number in phpmyadmin direct on the line null?or can i do it another way?
Hello, I'm trying to work out a method of displaying a pie chart depending on the values in an array by looping for a different value of $i, here's what I have so far: for($i = 0; $i < 11; $i++) { $colour = $i; $fraction = ($pie_data[$i]/$total); $pie_angle = $fraction*360; ImageFilledArc($myImage, 100, 100, 200, 180, STARTANGLE, ENDANGLE, $colour, IMG_ARC_PIE); } As you can see I've got fractions, which I'm converting into an angle. However, I can't think of a way to have the startangle and endangle parameters of the ImageFilledArc function depend on all of the previous pie angles, because I'm hoping this pie chart can vary as pieces of data forming each wedge (and each fraction) change. Can anybody help with this? Thanks so much for your help. I have a page that gets the closest stores to a latitude and longitude. I want to have a MySQL table like this: location_id:::::items showing how many items are at each store and then show 'spit' them in the following format with the lowest number of items first: location_id, distance to location_id, items. here is the code I am using to show location_id by distance Code: [Select] <?php include "connectionfile.php"; $lat = $_GET["lat"]; $lng = $_GET["lng"]; $sql = mysql_query("SELECT id, ( 6371 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance FROM locations HAVING distance < 250 ORDER BY distance LIMIT 0 , 60; "); WHILE($lstlocations = mysql_fetch_array($sql)) { $location_id[$count]=$lstlocations['id']; $distance=$lstlocations['distance']; echo "id = " . $location_id[$count] . " Distance = " . $distance. "<br>"; $count = $count + 1; } ?> What would be the best way to achieve this? I'm new at PHP and have a problem. I have a MySql database with lists of students grouped into classrooms. A typical group is shown in the attached screenshot screenshot.docx. I want to be able to select one or more of the names by using the associated checkbox, and upgrade a student or students into a different group as defined in the radio button list also in the screenshot. I have the rudiments of the file attached, but I have absolutely no idea how I can post the array so that the records are updated. Each student has an individual record with a field name userGroup which holds a string nominated by their classroom teacher, such as "year7", "year 8" and so on while they are in one of the several classrooms, but when they leave school this is recorded in a field named noGroup with a value of 0 or 1. I can post further details as required, but it would be great if someone could help me. I have a problem that occurred only recently, apparently by some change my webhost made on the server. Some time ago I wrote a script that simulates a Poedit-type editor. The script has about 1500 textareas (the translation fields) with unique names, dynamically generated. All worked fine. Now suddenly I get errors (see below) when I use more than 1000 textareas. It is not a problem of $_POST size, if happens also with empty textareas. I will show here a simple php test file that I called testta.php, which creates the same error as my much more complicated real script: Code: [Select] <?php if(isset($_POST['test'])) { echo 'The textareas were posted successfully!<br>'; } $max = 1500; echo '<form action="testta.php" method="POST">'; echo '<input type="submit" name="test" value="Submit"><br>'; for($i=0; $i < $max; $i++) { echo '<textarea name="test'.$i.'">name is test'.$i.'</textarea><br>'; } echo '</form>'; ?> The error message generated in the browser: 500 Server Error: A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again. From the Apache log file: [Sat Apr 28 12:47:48 2012] [error] [client 93.172.175.50] Premature end of script headers: testta.php, referer: http://****/*****/testta.php (stars added for privacy) When $max is set to a number < 1000 it works. On the web I have only found answers that deal with max size of posts, but as I mentioned that is not my case. My webhost can't help me out either. Until last Friday all worked fine. Does anyone know what server setting could create this problem? Thanks in advance, Kathy I am a new guy here and don,t have much knowledge of PHP. My problem is complex but let me explain it in simple lines. I have two different codes , 1) This code takes form entries 'website','caption' and 'name' and stores it into the Table named as 'user_info' into mysql database. This page is saved as index.php 2) This code can add add new category as a root or a child of existing category with update(edit & delete) option.This page is saved as categories.php Both codes are working(except upload function),but what i want to do is to combine the both forms (Items and category) into one page so that a user can add : webite :Its any URL caption: Description of website name: name of the person Add category:choosing existing category Add new category:If not exist add new category Tell me how can i combine both codes so that my item entries display under their categories???? 1) code for items -stores in Table 'user_info' <html> <head> <style type="text/css"> body { margin-left: 10.5%; margin-right: 10%; margin-top: 1%;} </style> <style type="text/css"> .italic { font-style:italic; color: #336666; font-family: Calibri; padding:20px; } .bold { font-weight:bold; } </style> <title>submit Bookmarks</title> </head> <body background="wrapper.png"> <form action="index.php" method="post"> <font face="Calibri">Add Your Links Here: </font> <input name="website" maxlength="100" size="58" value="http://www."> <p><font face="Calibri">Description: </font> <input name="caption" maxlength="100" size="58"> </p> <p><font face="Calibri">Your Name: </font> <input name="name" maxlength="100" size="28"> <input type="submit" name="Submit" value="Submit"> <font size="4"> </font></p> <p><font size="4"> OR </font><font color="#008080" size="2"><b><a href="soon.html"> <span style="text-decoration: none"><font color="#008080" face="Calibri">Upload</font></span></a></b></font>|<i><font size="2" face="Calibri">upload your Bookmarks from your computer. e.g., , .Csv,.txt or .mdb files.</font></i></p> <form action='upload.php' method='post'> <input type="hidden" name="sel_file" /> <font face="Calibri">Choose a file: </font> <input name="uploaded_file" type="file" /> <input type="submit" value="Upload" /> </form> </p> </form> </body></html> <?php $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "Password"; // change to your database password $database = "database-name"; // provide your database name $db_table = "user_info"; // # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); ?> <html> <head> <title>Add Your Bookmarks Here</title> </head> <body> <?php if (isset($_REQUEST['Submit'])) { # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(name,website,caption) values ('".mysql_real_escape_string(stripslashes($_REQUEST['name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['website']))."','".mysql_real_escape_string(stripslashes($_REQUEST['caption']))."')"; $query_auto = "INSERT INTO user_info (entry_date, col_date) VALUE ('DATE: Auto CURDATE()', CURDATE() )"; if($result = mysql_query($sql ,$db)) { echo 'Thank you, your information has been entered into our database<br><br>'; } else { echo "ERROR: ".mysql_error(); } } else { ?> <?php } ?> <?php if(isset($_POST['SUBMIT'])) { $fname = $_FILES['sel_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['sel_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into user_info(name,website,caption) values('$data[0]','$data[1]','$data[2]')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> <?php $result = mysql_query("select * from user_info ORDER BY CUR_TIMESTAMP desc"); // Database Query result ?> <?php while ($row = mysql_fetch_array ($result)) { $i++; if ($i & 1) { echo " <div class='color1'> <br/> <span class='bold'>Website:</span> <span class='normalfont' ><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . " </span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> </div>"; } else { echo " <div class='color2'> <br/> <br/> <span class='bold'>Website:</span> <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span> <br/> <span class='bold'>Description:</span> <span class='normalfont'>" . $row['caption'] . "</span><span class='italic'>Added by: " . $row['name'] . "</span> <br/> <br/> </div>"; } } ?> </body> 2) Code for Adding Categories <?php error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Categories Class</title> <style> .code_div{ border:dashed #006600 1px; background:#E8FFEB; font-family:Georgia, "Times New Roman", Times, serif; font-size:11px; width:90%; padding:5px; } </style> </head> <body style="font-family:Tahoma"> <p> <?php // connect to database $hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost $db_user = "username"; // change to your database password $db_password = "password"; // change to your database password $database = "batabase-name"; // provide your database name $db_table = "categories"; // leave this as is # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); require_once("categories.class.php"); // Simple Usage if(!isset($_GET["id"])) $_GET["id"] =0; $ctg_id = $_GET["id"]; $categories = new categories; $categories->name_prefix = " "; ?> </p> <p>Here is it a Html Menu:</p> <br> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; </font></font><br><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">;</font></font></code> </div> <p> <? // lets display the categories $output = $categories->html_output($ctg_id); echo $output; ?> </p> <hr> <p>now I'll modify the $HtmlTree value a bit.</p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">HtmlTree </font><font color="#007700">= array( <br> </font><font color="#dd0000">"header" </font><font color="#007700">=> </font><font color="#dd0000">"<table width=200px border=0 cellpadding=2 cellspacing=2>"</font><font color="#007700">, <br> </font><font color="#dd0000">"BodyUnselected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor=#C4D9FD >[prefix]&raquo;<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"BodySelected" </font><font color="#007700">=> </font><font color="#dd0000">'<tr><td bgcolor="#E4DB2C">[prefix]&bull;<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>'</font><font color="#007700">, <br> </font><font color="#dd0000">"footer" </font><font color="#007700">=> </font><font color="#dd0000">'</table>'</font><font color="#007700">, <br> ); <br> <br> </font><font color="#0000bb">$output </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$ctg_id</font><font color="#007700">); <br> echo </font><font color="#0000bb">$output</font><font color="#007700">; </font></font></code> </div> <?php $categories->HtmlTree = array( "header" => "<table width=200px border=0 cellpadding=2 cellspacing=2>", "BodyUnselected" => '<tr><td bgcolor=#C4D9FD >[prefix]»<a href="?id=[id]"><font color=#53507A>[name]</font></a></td></tr>', "BodySelected" => '<tr><td bgcolor="#E4DB2C">[prefix]•<a href="?id=[id]"><strong><font color="#000000">[name]</font></strong></a></td></tr>', "footer" => '</table>', ); $output = $categories->html_output($ctg_id); echo $output; ?> <hr> <? // lets get an array of the categories for our works $categories = new categories; $categories_list = $categories->build_list(); // lets do some actions if(!isset($_REQUEST['act'])) $_REQUEST['act'] = ""; $act = $_REQUEST["act"]; switch($act) { case "add": // lets add new category // $categories->add_new( category parent , category name , description , icon path , group ) $categories->add_new($_POST['parent'] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was inserted successfully into database"); location="class_categories_test.php"; </script>'; break; case "delete": $categories->delete($_GET["id"]); echo '<script>alert("Category and Sub-Categories was successfully deleted"); location="class_categories_test.php"; </script>'; break; case "_update": $cat = $categories->fetch($_GET["id"]); ?> <form name="form1" method="post" action=""> <p> the form below will execute the following. <br> </p> <div class="code_div"> <code><font color="#000000"><font color="#007700"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">update</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"id"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"parent"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] );</font></font></code> </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3"><div align="center">Edit Category </div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"> <select name="parent" id="parent"> <option value="0" selected>ROOT</option> <? foreach($categories_list as $c) { if($cat["id"] == $c["id"]) continue; // we don't list the category to be child of itself !! ?> <option value="<?=$c["id"]?>" <? if($c["id"] == $cat["parent"]) echo "selected"; ?> ><?=$c["prefix"]?>»<?=$c["c_name"]?></option> <? } ?> </select> </td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" value="<?=$cat["c_name"]?>" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"><?=$cat["c_desc"]?> </textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="<?=$cat["c_icon"]?>" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="update"> <input name="id" type="hidden" value="<?=$ctg_id?>"> <input type="submit" name="Submit" value="Save"> </div></td> </tr> </table> </form> <? die(); break; case "update": $categories->update($_POST["id"] , $_POST["parent"] , $_POST["name"] , $_POST["desc"] , $_POST["icon"] ); echo '<script>alert("Category was updated successfully!"); location="class_categories_test.php"; </script>'; break; } ?> <p align="center"> </p> <p align="center"><strong>You may list all your categories expanded like this</strong></p> <div class="code_div"> <code><font color="#000000"><font color="#0000bb">$categories </font><font color="#007700">= new </font><font color="#0000bb">categories</font><font color="#007700">; <br> </font><font color="#0000bb">$categories_list </font><font color="#007700">= </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">build_list</font><font color="#007700">(0);</font></font></code> <br>// $categories_list is now an array and you should use foreach command to print something like the following list. </div> <br> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td bgcolor="#4180BE"><font color="#FFFFFF"><strong> Categories List: </strong></font></td> </tr> <? foreach($categories_list as $c) { ?> <tr> <td> <?=$c["prefix"]?>»<?=$c["c_name"]?> - [<a href="?act=_update&id=<?=$c["id"]?>">Edit</a> - <a href="?act=delete&id=<?=$c["id"]?>">Delete</a>] </td> </tr> <? } ?> </table> <p align="center"> </p> <p align="center"><strong>Or you may also use it in a combo box</strong></p> <table width="0" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td width="72"><select name="category_id" id="category_id"> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>"><?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> <td width="0"><input type="button" name="Button" value="Edit" onClick="location='class_categories_test.php?act=_update&id='+document.getElementById('category_id').value;"></td> <td width="0"><input type="button" name="Button" value="Delete" onClick="location='class_categories_test.php?act=delete&id='+document.getElementById('category_id').value;"></td> </tr> </table> <p> </p> <p><hr></p> <form name="form1" method="post" action=""> the form below will execute the following. <br> <div class="code_div"> <code><font color="#000000"><font color="#ff8000"> </font><font color="#0000bb">$categories</font><font color="#007700">-></font><font color="#0000bb">add_new</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">'parent'</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"name"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"desc"</font><font color="#007700">] , </font><font color="#0000bb">$_POST</font><font color="#007700">[</font><font color="#dd0000">"icon"</font><font color="#007700">] ); </font></font></code></div><br> <table width="400" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="3" bgcolor="#4180BE"><div align="center"><strong><font color="#FFFFFF">Add New Category </font></strong></div></td> </tr> <tr> <td width="13%">Child Of : </td> <td width="1%">:</td> <td width="86%"><select name="parent" id="parent"> <option value="0">ROOT</option> <? foreach($categories_list as $c) { ?> <option value="<?=$c["id"]?>" > <?=$c["prefix"]?>»<?=$c["c_name"]?> </option> <? } ?> </select></td> </tr> <tr> <td>Name:</td> <td>:</td> <td><input name="name" type="text" id="name" size="20"></td> </tr> <tr> <td>Description:</td> <td>:</td> <td><textarea name="desc" cols="40" rows="3" id="desc"></textarea></td> </tr> <tr> <td>Icon:</td> <td>:</td> <td><input name="icon" type="text" id="icon" value="http://" size="30"></td> </tr> <tr> <td colspan="3"><div align="right"> <input name="act" type="hidden" value="add"> <input type="submit" name="Submit" value="Add"> </div></td> </tr> </table> </form> <p align="center"> </p> </body> </html> Sorry for making this long post,hope u won,t mind :-) and will solve my problem This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=334133.0 I am trying to do something like this but the code I have doesn't seem to do what I want... Code: [Select] <?php while($item_rows = mysql_fetch_array($item_result)) { $output = " <tr bgcolor=\"#000000\"> <td align=\"center\"><p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p> <p>".$item_rows['name']."<br /> Attack: +".$item_rows['attack']."<br /> <img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p> <p>[Equipt|Destory]<br /> </p> </td>"; $remainder = $i % 5; echo ($remainder == 0 ? ($i == 0 ? "" : "\n</tr>")."\n$output " : $output); } $colspan = (4 - $remainder); $last_row = $colspan ? " <td ".($colspan? "colspan=$colspan" : "")."></td>" : ""; echo $last_row. " </tr> </table>"; ?> This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=346405.0 I'm trying to make it so that someone can add an item to the shop based upon the current items within the database. How do I go about doing that? I know i have to change <input> to <select>, but beyond that, how do I code it so I can run an array to get all the current items from the table `items` and list them by their `name` field? Thanks in advance! Here is what I have so far: function addshopinv($id) { error_reporting(E_ALL); ini_set('display_errors', 1); if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($name == "") { $errors++; $errorlist .= "Name is required.<br />"; } else if ($errors == 0) { $dbh=dbconnect() or die ("Userlist read error: " . mysql_error()."<br>"); mysql_select_db("XXX"); $query = mysql_query("SELECT id FROM items WHERE name='$name'"); while ($result = mysql_fetch_array($query)){ $item_id = $result['id']; $query1 = mysql_query("INSERT INTO sale SET shop_id='$id', item_id='$item_id'"); } admindisplay("Inventory Item Added.","Add New Inventory Item"); } else { admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.", "Add New Item to Shop"); } } $page = <<<END <b><u>Add New Inventory Item</u></b><br /><br /> <form action="admin_panel.php?do=addshopinv:$id" method="post"> <table width="90%"> <tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="255" value="" />*255 character max</td></tr> </table> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> END; $page = parsetemplate($page, $row); admindisplay($page, "Add New Inventory Item"); } I have a php page where I have posts about different topic. I have a menu listing all this categories of topics . Some topics may belong to more than one category. So when i click on a particular menu item, the topic belonging to that category will be displayed. While displaying it is in this format---Topic Heading,Belongs to which all categories,date posted and the description. All this are taken from database. Now my actual issue is I am not able to give links to the categories dispalyed ,if the category exceeds more than 1. For eg: Global Warming Posted on March 11,2011 in News, Issue -----------description of global warming goes here. In the above eg: News and issue are the two categories,when i click on News it should display all the items in news category,and when i click on issue it should display all items of issue category. But I am not able to give this link to the categories. Code: [Select] while($row = mysql_fetch_array($q)) { if($row[6]=='News'){ $c='<a href="category_disp.php?category=news">News</a>'; } if($row[6]=='Issues'){ $c='<a href="category_disp.php?category=issues">Issues</a>'; } echo "<tr><td><p >$row[1]</p><br></td></tr>"; echo "<tr><td> <div >". "<p><span>$row[4]</span> <span>". "<a href='$row[6]' >$row[6]|<a href='$row[5]'> Post Comments</a></span></p>". "<p> </p></div><br></td></tr>"; echo "<tr><td><p >$row[2]</p><br></td></tr>"; echo "<tr><td><p ><a href='$row[3]' >Click Here to read more...</a></p></td></tr>"; echo "</div></td></tr>"; } echo" </table> I want to retrieve items from the DB and seperate them using a comma... while i know how to actually do that, what i want is to automatically have stop adding comas at the last item... so if there are 4 items i want it to show a comma after each item except the last one (1, 2, 3, 4). Does anyone know of a function or can give me an example on how i can do this. I coded the following but some parts are not working (the "curveball" mentioned at the end). How would YOU do this? I have a page (A) displaying a form with a textarea field using a WYSIWYG interface. The user will enter a list of unordered items and upon submit the string will look something like this: This is my list of food items: <ul> <li> Lettuce </li> <li> Tomatoes </li> <li> Eggs </li> <ul> Upon submit, I need to give each list item an unique id and store this id along with the text next to it in a separate table: List_item_id List_item_text List_item_state food_1 Lettuce food_2 Tomatoes food_3 Eggs The user will then land in another page with a form displaying the list. The text is now in the page itself and not in a textarea. Instead of the bullets a dropdown list appears, and the user can select "buy" or "sell" for each list item. This page (B) looks something like this: <form> This is my list of food items: <br><select name="food_1"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Lettuce <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Tomatoes <br><select name="food_2"> <option value="buy">Buy</option> <option value="sell">Sell</option> </select> Eggs <input type=submit value="submit"> </form> When the user hits "submit" the table with the list items will be updated with the values selected in the dropdown list: List_item_id List_item_text List_item_state food_1 Lettuce Buy food_2 Tomatoes Buy food_3 Eggs Sell The next time the user goes to Page B the list will remember the states. Here's the curveball: At any point the user may click on "EDIT LIST" on Page B so they may add more items (at the begining, middle or end of the string). On edit mode the list items should appear as bullets again inside the WYSIWYG interface. Keep in mind that some of the text in the string may not be a list item (ie, "this is my list of food...") I've been playing around with this code from http://v3.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart Objective: I'm trying to make the scripts work but without pulling the data from MySQL Database. Instead, I created an array and inserted some info there and trying to replicate the same results but getting confused. For example, on the Index.php file, I made the following changes: <?php // Start the session session_start(); // Include functions require_once('inc/functions.inc.php'); // Products multidimensional Array $products = array("book" => array( 'id' => '1', 'title' => 'Learn Your ABC\'s', 'author' => 'John Doe', 'price' => '14.95'), "video" => array('id' => '2', 'title' => 'Visual Guide to learn', 'author' => 'Adam Smith', 'price' => '21.38'), "puzzle" => array('id' => '3', 'title' => 'Can You Solve?', 'author' => 'Sara Brown', 'price' => '9.41'), "exam" => array('id' => '4', 'title' => 'Test Your Knowledge', 'author' => 'Kim Carver', 'price' => '11.15')); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php /* $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); */ ?> <?php $output[] = '<ul>'; foreach ($products as $product => $product_item) { // $flavor is the key and $piece is the value foreach ($product_item as $item => $piece) { if ($item == "id") { # Conditional logic defined to map specific keys to specified name value $row['id'] = $piece; // echo "The id is ". $id."<br />"; // set just to confirm value correct for variable } elseif ($item == "title") { # Conditional logic defined to map 1st key to price value $row['title'] = $piece; // echo "The title is ". $title."<br />"; // set just to confirm value correct for variable } elseif ($item == "author") { # Conditional logic defined to map 1st key to price value $row['author'] = $piece; // echo "The author is ". $author."<br />"; // set just to confirm value correct for variable } elseif ($item == "price") { # Conditional logic defined to map 1st key to shipping value $row['price'] = $piece; // echo "Price: ". $price."<br /><br />"; // set just to confirm value correct for variable } $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; $output[] = '</ul>'; echo join('',$output); } } ?> </div> </body> </html> And here's the original index.php before my edits which show the sql query to the db: <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> Also, I included the zipped file of the entire script setup. Again, I'm trying to figure out how to make the cart work with using an array for the product instead of MySQL database. My goal is to remove ALL SQL statements from the scripts but stuck with the looping portion to display the title, author, and price from the array as shown above. Hi, What I'm trying to do is create a script that generates a random list of cars whenever it is run. I have a list of available cars in a MySQL database. I'm just not sure how to get php to generate a list of, say, 20 cars, that are randomly picked from the cars in the database. I may also want to add other statistics like MPG (also already in the database). Can anyone show me how to do this? And is it possible to format the returned data in a table or div format? Thanks in advance Unk Hi.. I encountered problem in displaying joborder number or JO_No inside while loop. I want to happen is only JO_No will display after I click the Approved button and it will only appear on the row where the Approved button was click. Now in my code the JO_No was display automatically in the row of JO_No . here is my code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Job Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table width="auto"> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> <?php $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); $Approved = isset($_POST['priority']); if ($Approved) { $PO_No = $_POST['PO_No']; //----I want to display only the jo_number after click the approved button and it only display on the row where I click the approved button--- $sql = "SELECT jo_number FROM job_order ORDER BY jo_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //---------------------------------------- $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['jo_number'],0,3)); $currentSRYear = (int)(substr($row['jo_number'],2,2)); $currentSRMonth = (int)(substr($row['jo_number'],0,2)); $currentSRNum = (int)(substr($row['jo_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); //JO_No } while($row = mysql_fetch_assoc($res_so)){ echo "<form name='joborder_form' action='' method='post'>"; $PO_No = $row['PO_No']; echo "<tr> <td><input type='text' name='JO_No' id='JO_No' value='$currentSR' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='ETD' id='ETD' value='$row[ETD]' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='PO_No' id='PO_No' value='$row[PO_No]' style='border:none;' size='30'></td> <td><input type='text' name='SKUCode' id='SKUCode' value='$row[SKUCode]' style='border:none;' size='15'></td> <td><input type='text' name='Description' id='Description' value='$row[Description]' style='border:none;' size='35'></td> <td><input type='text' name='POReq' id='POReq' value='$row[POReq]' style='border:none;width:auto;' size='10'></td> <td> </td> <td><input type='submit' name='priority' value='Approved' id='priority'></td> </tr>"; echo "</form>"; } ?> </table> </div> </body> </html> I attach the sample image of my form. Any help is highly appreciated Thank you |