PHP - Echo Table In New Row For Each Mysql Result
I am getting the row results from mysql as called, but they appear as a straight line instead of new table row when I echo like:
echo "TABLETABLETABLETABLE"; I am looking for: echo "TABLE TABLE TABLE TABLE"; Here is my code: Code: [Select] $brand = $_POST['brand']; $city = stripslashes($_POST['city']); $state = $_POST['state']; $zip_code = stripslashes($_POST['zip_code']); if($city !=""){ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE city ='".$city."' AND state ='".$state."' AND brand = '".$brand."'"; }else{ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE zip_code ='".$zip_code."'"; } $result = mysql_query($query); $count=mysql_num_rows($result); if($count==0 && $zip_code !=""){?> <td width="100%" class="style9">Sorry! There are no results for that city, state and brand.</td> <? }else{ while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ?> <td width="100%" class="style9"><?php echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td{$typ_image}</td> <td><b><a href=\"\" title=\"{$row['street']} {$row['city']}, {$row['state']}. {$row['zip_code']}\" target=\"_blank\">{$row['name']}</a></b><br>Last Updated:{$row['date']}</td> <td><b>{$row['brand']} - {$row['quantity']}</b><br>Before Tax:\${$row['price1']} After Tax:\${$row['price2']}</td> <td{$pago}</td> </tr> </table><BR>"; ?></td> <?php } } ?></table> <p> </p> </td> Similar TutorialsHi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt I am having so much trouble with this. I want to create a html table that looks like this: Code: [Select] <table id="datatable"> <thead> <tr> <th></th> <th>test</th> <th>test 2</th> </tr> </thead> <tbody> <tr> <th>2011-03-17</th><td>1</td><td>0</td> </tr> <tr> <th>2011-03-18</th><td>3</td><td>2</td> </tr> <tr> <th>2011-03-19</th><td>1</td><td>0</td> </tr> </tbody> </table> out of this mysql result: opens | name | date 1 | test | 2011-03-17 3 | test | 2011-03-18 2 | test 2 | 2011-03-18 1 | test 2 | 2011-03-19 Here is my mysql code: Code: [Select] SELECT count( o.campaign_id ) AS opens, c.name, date(o.created_at) as date FROM opens o LEFT JOIN campaigns c ON c.id = o.campaign_id WHERE (o.created_at between '2011-03-17 00:00:00' and '2011-03-19 23:59:59') GROUP BY date,c.name I also attached a sql dump of my database. Hi guys, How do I call the 2nd row of 'TSuperQuestion'? Code: [Select] <?PHP $con = mysql_connect("localhost","ph6theo", "xxxx"); if (!$con) { die('Could not connect: ' . mysql_error("oop")); } mysql_select_db("ph6theo_testDB") or die(mysql_error()); $result = mysql_query("SELECT * FROM QANDATable "); $row = mysql_fetch_array($result); echo $row['TSuperQuestion']; ?> Hi all, I have a number of tables within a mysql database and I'm stuck on how to pull information from one based on the results being displayed by another. The site shows items for sale where by all the product information is held in tablea, when an individual item is being displayed I need to be able to pull a manufacturer profile from tableb based on the manufacturer name stored in tablea column profile. The manufacturer name is already being called into the page by existing code as the site has always shown the manufacturer name, I just can't work out out to pull the new profile information in as well from the new table. Any help appreciated Iain Here is one part of php code. Here I try to show in last 1 month which dates exactly user made orders. When I run the SQL code in command prompt it works. I think problem is in while loop. Thanks beforhand for contribution. $query = "SELECT Date FROM orders WHERE User='$username' and DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Date;"; $result = mysql_query($query,$link_id) or die (mysql_error()); echo "<table border='1'> <tr> <td> Last 1 month's orders:</td> </tr>"; while($order_date = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $order_date[0] . "</td>"; echo "</tr>"; } echo "</table> How do you do this? Thanks in advance. Hi guys,
Here's my code:
<?php $servername="127.0.0.1"; $username="root"; $password=""; $dbname="testdb"; $connection = new mysqli($servername,$username,$password,$dbname); $sql = "SELECT Wages FROM w WHERE \"Country\"=\"".$_POST["blah"]."\""; $r = $connection->query($sql); $result = $r->fetch_all(MYSQLI_ASSOC); echo $result; ?>When I go to the page I get the following message: Notice: Undefined index: w in C:\xampp\htdocs\test\processing.php on line 13 Does anyone know what problem I'm having here? /stuck Cheers, B How can I check if a returned mysql value is equal to '' i.e. nothing? I keep getting an error where the page won't load because the returned value is '' so i need to check for it hello I'm using this code: Code: [Select] $query="SELECT * FROM `second_content` WHERE CHANGED =0 limit 0,1";to query first row data when I want see it and echo it I recived : Code: [Select] Resource id #2can anyone help me ? thank you Hello, i created this script for a client and have ran into an annoying error with the results displaying on a new line for each result instead of side by side, any help is welcome Cheers Code: [Select] <?php $subcat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['subcat'])))); $cat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['cat'])))); $sql = @mysql_query("SELECT * FROM cakes WHERE category =\"$cat\" AND sub_cat=\"$subcat\" ORDER BY id DESC"); while ($row = mysql_fetch_array($sql)) { $reference = $row['reference']; $image = $row['image']; echo ("<p><img src='./images/cakes/$image' height='289px' width='177px' alt='IMAGE OF CAKE'></img><br />"); echo ("<b>Reference:</b>$reference"."</p>"); } if (!$reference) { echo 'There are no cakes in this category yet.'; } ?> I know the errors only going to be something small i'm missing, but i've been coding all day Hi, I don't know anything about php and Mysql but I found a tutorial for a shopping cart and everything is working. The only thing is they don't have the email part in the totorial so I'm kind of stuck with my file. Anyone know how to email the resul to me via email with this code? <? include("includes/db.php"); include("includes/functions.php"); if($_REQUEST['command']=='update'){ $name=$_REQUEST['name']; $email=$_REQUEST['email']; $address=$_REQUEST['address']; $phone=$_REQUEST['phone']; $result=mysql_query("insert into customers values('','$name','$email','$address','$phone')"); $customerid=mysql_insert_id(); $date=date('Y-m-d'); $result=mysql_query("insert into orders values('','$date','$customerid')"); $orderid=mysql_insert_id(); $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $price=get_price($pid); mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)"); } die('Thank You! your order has been placed!'); } ?> <!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>Billing Info</title> <script language="javascript"> function validate(){ var f=document.form1; if(f.name.value==''){ alert('Your name is required'); f.name.focus(); return false; } f.command.value='update'; f.submit(); } </script> </head> <body> <form name="form1" onsubmit="return validate()"> <input type="hidden" name="command" /> <div align="center"> <h1 align="center">Billing information</h1> <table border="0" cellpadding="2px"> <tr><td>Total:</td><td><?=get_order_total()?></td></tr> <tr><td>Name :</td><td><input type="text" name="name" /></td></tr> <tr><td>Address :</td><td><input type="text" name="address" /></td></tr> <tr><td>Email :</td><td><input type="text" name="email" /></td></tr> <tr><td>Phone :</td><td><input type="text" name="phone" /></td></tr> <tr><td> </td><td><input type="submit" value="Place Order" /></td></tr> </table> </div> </form> </body> </html> Im not sure where to post this but since it includes php il post it here instead of in the mysql forum. ok so, i have a table and i get the values using while($row = mysql_fetch_array($result)){ and then echo them in rows. that works fine but i need to add a class to the last row of my table. I would need somehow to fetch the last row of the array and make it echo something different. Any help is appreciated Thank you Hello Everyone, I have a quick question for you all, I think its fairly simple... I have created a database and I am using PHP to grab the data: $usera = $_SESSION['username']; $query2 = "SELECT * FROM tracker WHERE id = '$usera', hidden = yes"; mysql_query($query2) or die('Error, query failed : ' . mysql_error()); This hopefully will return multiple rows which look like this in the database. id username date reps hidden 1 supremebeing 2011-01-02 30 yes 4 supremebeing 2011-04-02 46 yes How would i turn each result into a variable eg: $date1 = 2011-01-02; $date2 = 2011-04-02; $reps1 = 30; $reps2 = 46; I think i have explained that well enough for you to understand, please reply if not though and i will provide more information. Thanks in Advance hey guys, i need some help with my php/mysql iplogger. My code: <?php //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //conects to the mysql server $connection = mysql_connect('localhost', 'root', ''); //sellects the database mysql_select_db('iplog', $connection); //looks for duplacute ips $dup = mysql_query("SELECT COUNT(number) FROM logged_ips WHERE ip_address = '$ip'",$connection); $count = mysql_result($dup, 0); //checks to see if there is a duplecate name if ($count == 0){ //inserts the ip in to the database $string = 'INSERT INTO `logged_ips` (`aid`, `ip_address`, `ip_visits`) VALUES (\'' . null . '\', \'' . $ip . '\', \'0\')'; mysql_query($string, $connection); }else{ //adds a visit to the database $string2 = "UPDATE `logged_ips` SET `ip_visits` = '++1' WHERE `ip_address` = $ip LIMIT 0,1"; mysql_query($string2, $connection); } //outputs the ip echo $ip; ?> error: Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\randoms\logger\test.php on line 11 127.0.0.1 It also doesnt put anything in to the mysql database. Please help. Thanks jragon Hey guys, Currently Im using: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['user_family']. " - ". $row['user_registered']; $row['user_family'] = $fam; $_SESSION['family'] = $fam; to take data from a mysql table & set it as SESSION family. However, I cant seem to get this to set. The information IS being taken from mysql because its being echo'd earlier up in the code, but its just not passing to the session. Any ideas? I am having a little bit of trouble with this piece of code. I'm sure it's something simple, but I have been working on this thing all day and want to get it finally finished. Here's the troublesome code: function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } $sql_clean = "SELECT * complete WHERE createdate < date_sub(current_date, interval 1 minute)"; $sql_list = mysql_query($sql_clean); while($row = mysql_fetch_assoc($sql_list)) { $directory = "complete/" . $row['fileurl']; rrmdir($directory); } The purpose of this particular bit is to run on a cron every few days. It gets "createdate" and other info from the "complete" table in order to know how old the record is. If the record is older than (in the example, 1 minute; it will be set to several days on public) the defined max age, it removes that directory and everything within it to keep the directory clean and the disk usage down. The error returned is Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/latenit2/public_html/kindleprocessor/process/garbagecleaner.php on line 46 Line 46 is Quote while($row = mysql_fetch_assoc($sql_list)) { I may be doing the look-up on the MySQL database incorrectly, too. I haven't discounted that, and I'd be thankful if someone could help me out with this issue. I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty Hi, I'm trying to make a mysql output to a link so the name will be a link so when you hit this link you will get the full information of this mysql input. Can someone point me in the correct direction? Here is how i get the output from my mysql database into my table. Code: [Select] <td>"; echo $row['name']; echo "</td> Hi, I am new to php but not to programming. I created a script on a windows platform which connects to the mysql database and returns the results of a table. A very basic script which I wrote to simply test my connection worked. The script works fine on my windows machine but not on my new mac. On the mac it simply does not display any records at all. I know that the database connection has been established because there is no error but I can not see why the result set is not being displayed on screen, as I said it worked fine on my windows machine. The Mac has mysql (with data) and apache running for php. Please could someone help as I have no idea what to do now? Script below: Code: [Select] $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_select_db("test", $conn); $result = mysql_query("SELECT * FROM new_table"); while($row = mysql_fetch_array($result)) { echo $row['test1'] . " " . $row['test2'] . " " . $row['test3']; echo "<br />"; } mysql_close($con); |