PHP - Using Php To Add Rows To A Form
Hey everyone,
I just started using php a couple days ago and I've run into an issue. This is also my first time coding anything, so even basic things are a bit difficult for me. What I have posted below is an html form with 5 fields. After typing values (into as many or as little fields as you want) and hitting "submit", the form will echo how many values you've entered (integers, strings, whatever, it'll add one to the counter as long as the value isn't negative). The values will also remain in the form after being submitted (this is intentional, and actually what I'm after). This is working just fine. What I'm trying to add is an option to switch between a maximum of either 5 fields (rows), or 10 fields. The code below manages to do this, and actually return the correct result after hitting "submit". Unfortunately, it won't "hold onto" any of the values I enter past the original 5 fields. So for example if I switch to 10 fields, and enter "1, 2, 3, 4, 5, 6, and 7" into the fields, it will display "7 items", however, only the "1, 2, 3, 4, and 5" will remain in their respective fields, while the "6, and 7" will disappear. So, two questions. First, how do I fix that? And second, what's actually the best way for me to do what I'm trying to do? Because I'm guessing I've come up with a pretty bad newbie hacked-together way of doing it (Note: This is all part of a larger function that has proper data sanitation and etc, I just cut it down for this example.) Thanks! Edit: I'd also like to add I ideally want this entirely in php (no javascript) for compatibility reasons. <?php // rows.php $a[1] = $a[2] = $a[3] = $a[4] = $a[5] = $a[6] = $a[7] = $a[8] = $a[9] = $a[10] = $rows = $r10 = ''; $r5 = 'checked'; if ($r5 == 'checked') { $start_r_cnt = 1; $end_r_cnt = 5; } if (isset($_POST['rows'])) { $check_radio = $_POST['rows']; if ($check_radio == 'r10') { $r10 = 'checked'; $start_r_cnt = 1; $end_r_cnt = 10; for ($i=6;$i<=$end_r_cnt;$i++) { $value = "$a[$i]"; $rows = $rows.'<tr><td><input type="text" name="a'.$i.'" size="10" value="'.$value.'"/></td></tr>'; $value = $a[$i]; } } } $count_a = 0; $value_error = ''; for($i=1;$i<=$end_r_cnt;$i++) { if(isset($_POST['a'.$i])) { $a[$i] = $_POST['a'.$i]; if($a[$i] == '') { $a[$i] == ''; } elseif($a[$i] >= 0) { $count_a++; } elseif ($a[$i] < 0) { $value_error = 'One of the entered values is negative. Please fix this before continuing.'; } } } echo <<<_END <html> <form method="post" action="rows.php"> <table cellpadding="5"> <b>Number of Rows:</b><br> <input type="submit" name="rows" value="Change" style="width: 70px" /> [5]<input type='radio' name='rows' value='r5' $r5/>[10]<input type='radio' name='rows' value='r10' $r10/> <tr><td><center>Data A</center></td></tr> <tr><td><input type="text" name="a1" size="10" value='$a[1]'/></td></tr> <tr><td><input type="text" name="a2" size="10" value='$a[2]'/></td></tr> <tr><td><input type="text" name="a3" size="10" value='$a[3]'/></td></tr> <tr><td><input type="text" name="a4" size="10" value='$a[4]'/></td></tr> <tr><td><input type="text" name="a5" size="10" value='$a[5]'/></td></tr> $rows <tr><td><center><input type="submit" value="Submit" style="width: 80px" /></center></td></tr> </table> <b>$count_a</b> items are present. <b>$value_error</b> </html> _END; ?> Similar TutorialsHey. Third question today. Very stuck on this one. I am displaying a ton of while loops to display a bunch of data from two different tables. there is NO possible way i can combine the two tables. I mean, I can, but I'm not going to because they are two totally different thins. Anyway. Here is what I'm trying to do: Lets say I have 3 items, a grape, an orange and an apple. - 3 apples - 2 oranges - 1 grape I'm displaying an update price box for each different fruit. (so 3 different boxes), and one submit button. I update it, and it does update the price but it only updates the very first row. I want to be able to update every row I types the price in for. Here is my code: (it is quite long): Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<banner></banner><nav>$shownavbar</nav><ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar>$ubear</ubar><content><center><font size=6>User Shops</font><br><br>"; $action = $_GET['action']; if(!isset($action)) { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br>"; } if(isset($action)) { $getshopq = "SELECT * FROM usershops WHERE owner='$showusername'"; $getshop = mysql_query($getshopq); while($tri = mysql_fetch_array($getshop)) { $theid = $tri['ushopid']; $owner = $tri ['owner']; $desc = $tri['description']; $image = $tri['image']; $name = $tri['name']; $status = $tri['status']; $discount = $tri['discount']; } $countq = "SELECT * FROM usershops WHERE owner='$showusername'"; $countit = mysql_query($countq); if($action == "edit") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Edit Shop</font><br><br>"; if(mysql_num_rows($countit)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <?php } if(!mysql_num_rows($countit)) { $create = $_POST['create']; $thename = $_POST['thename']; $thedesc = $_POST['thedesc']; $thestatus = $_POST['thestatus']; $theimage = $_POST['theimage']; if(!isset($create)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if(isset($create)) { if($thename == "" || $thedesc == "") { echo "<font color=red>Error! Please fill out the entire form!</font><br><br>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Shop Name: <input type="text" name="thename"><br>Description<br><textarea name="thedesc" rows="5" cols="25"></textarea><br> Status: <select name="thestatus"> <option>Open</option> <option>Closed</option> <option>Gallery</option> </select><br><br> <input type="submit" name="create" value="Create Shop"></form> <?php } if($thename != "" && $thedesc != "") { mysql_query("INSERT INTO usershops (owner, name, description, image, status, discount) VALUES ('$showusername', '$thename', '$thedesc', 'image.gif', '$thestatus', 'None')"); echo "<font color=green>Success! You have created your shop! Click <a href=?action=view>here</a> to view it.</font><br><br>"; } } } } if($action == "view") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Shop Name Here</font><br><br>"; $wowq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2'"; $wow = mysql_query($wowq); while($wrow = mysql_fetch_array($wow)) { $umid = $wrow['uitemid']; $umiid = $wrow['theitemid']; $umloc = $wrow['location']; $umprice = $wrow['price']; $infoq = "SELECT * FROM items WHERE itemid='$umiid'"; $info = mysql_query($infoq); while($row = mysql_fetch_array($info)) { $myname = $row['name']; $myid = $row['itemid']; $myimage = $row['image']; $mydesc = $ow['description']; $myrarity = $row['rarity']; echo "$myname"; } } } if($action == "stock") { $setprice = $_POST['price']; $updateprice = $_POST['updateprice']; echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Stock Shop</font><br><br>"; $eq = "SELECT * FROM uitems WHERE username='$showusername' AND location='2' GROUP BY theitemid"; $ee = mysql_query($eq); while($erow = mysql_fetch_array($ee)) { $eeloc = $erow['location']; $eeid = $erow['theitemid']; $eenowid = $erow['uitemid']; $eeprice = $erow['price']; $wq = "SELECT * FROM items WHERE itemid='$eeid'"; $ww = mysql_query($wq); while($wrow = mysql_fetch_array($ww)) { $cq = mysql_query("SELECT * FROM uitems WHERE username='$showusername' AND location='2' AND theitemid='$eeid'"); $lcq = mysql_num_rows($cq); $fid = $wrow['itemid']; $fname = $wrow['name']; $fimage = $wrow['image']; $frarity = $wrow['rarity']; $fdesc = $wrow['description']; echo "$fname<br><img src=/images/items/$fimage>"; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="text" name="price" maxlength="5"><br><br> <?php } } if(isset($updateprice)) { mysql_query("UPDATE uitems SET price='$setprice' WHERE username='$showusername' AND theitemid='$fid'"); echo "<font color=green>Success! Your prices have been set and updated!</font>"; } ?> <input type="submit" name="updateprice" value="Update Prices"> <br> <?php } if($action == "quick") { echo "<a href=?action=edit>Edit Shop</a> | <a href=?action=view&user=$showusername>View Shop</a> | <a href=?action=stock>View Stock</a> | <a href=?action=quick>Quick Stock</a><br><br><font size=5>Quick Stock</font><br><br>"; } } } ?> </html> To help you find it, I'm asking about the "stock" $_GET part, about three quarters down. Thanks in advance for anybody who can help me, I've been stuck on this script all day! Thanks again! The information is drawn in from a table into a form that the user will click submit and all the rows will be inputted into the table with their username association. With this form, its only inputting the last row and not all of them. You're help is much appreciated! Here is the form in the PHP area: while($row=mysql_fetch_array($get_items_sql)){ $name =$row['item']; $date = ($row['expiration_date']); $exp_date = date('M d Y', strtotime($row['expiration_date'])); $content .= ""; $content .="<table width=\"450\" border=\"0\"><tr><td width=\"200\"><span class=\"anotherfont\"><input name=\"item[]\" type=\"hidden\" value=\"$name\" id=\"item[]\">$name</span></td><td width=\"200\"><span class=\"greenfont\"><input name=\"expiration_date[]\" type=\"hidden\" value=\"$date\" id=\"expiration_date[]\">$exp_date</span><input name=\"username[]\" type=\"hidden\" value=\"$username\" id=\"username[]\"/> </td></tr><br /></table>"; $content .= "\n"; } $content .= "</ul>\n"; Then below is part of the HTML Form with $content referenced: <form action="add_select.php?source_id=<?php echo $coupon_source ?>" method="post" enctype="multipart/form-data" name="add_new" id="add_new"> <?php echo $content ?> <input name="SUBMIT" type="submit" value="submit" /></form><br /> Then here is the section from the "add_select.php" file from the form: include('connect.php'); foreach($_POST['item'] as $row=>$item) { $Item_name=$item; $expiration_date=$_POST['expiration_date'][$row]; $username=$_POST['username'][$row]; } foreach($_POST['item'] as $row=>$item) { $Item_name=mysql_real_escape_string($item); $expiration_date=mysql_real_escape_string($_POST['expiration_date'][$row]); $username=mysql_real_escape_string($_POST['username'][$row]); } $sql2="INSERT INTO place (item, expiration_date, username) VALUES ('$Item_name', '$expiration_date', '$username')"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }else { header("location:insert_complete.php"); } Hi, I want to update a txt files 10. row with a form but I could not it how can I do it? The table is: next next_id id 0 2 1 1 3 2 0 4 3 0 1 4 The form: <?php include 'dbc.php'; page_protect(); if(!checkAdmin()) { header("Location: login.php"); exit(); } if($_POST['doSubmit'] == 'Create') { list($next_id) = mysql_fetch_row(mysql_query("select next_id from users where id='$id'")); mysql_query("update users set approved='1' where id='$id'"); mysql_query("update users set next='1' where id='$next_id'"); mysql_query("update users set next='0' where id='$id'"); list($to_email) = mysql_fetch_row(mysql_query("select user_email from users where id='$id'")); $ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str']; header("Location: $ret"); exit(); $message = "Hello \n "; @mail($to_email, "Aaaaack", $message, "From: \"Lobo\" <auto-reply@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); } ?> Code: [Select] <html> <body> <table width="80%" border="0" cellpadding="5" cellspacing="2" class="myaccount"> <tr> <td>i<form name="form1" method="post" action="form.php"> <input name="doSubmit" type="submit" id="doSubmit" value="Create"> </p> </form> </td> </tr> </table> </body></html> I am sorry if this is posted in the wrong place! Here to learn. Thank you for any clues! Please help me. I'm fairly new to php and have been looking for answers on Goog for about two weeks or so with not an answer. This is my first post on a forum of any type. I have a form on a php page that when submitted sends a value to a confirm php page Code: [Select] <form action='buyconfirmorder.php' method='post'> Purchase: <input type='text' name='ask_shares'><br /><br /> You Will Pay:  <input type='text' name='ask'><br /><br /> <input type='hidden' name='postcardname' value='$postcardname'> <input type='submit' name='submit' value='Order'> </form> I need to take the users input from the form and subtract each row from a mysql DB one at a time until the users input is down to a remainder and then I need the remainder (I'll be working with the remainder as well). Code: [Select] $query = mysql_query(" SELECT * FROM ask, search WHERE search.id = ask.card_search_id AND search.card_name = '$postcardname' ORDER BY ask_price ASC"); The array will be numbers only. So an example would be: User input from the form is 100.00 Code: [Select] while($rows = mysql_fetch_array($query)) { $ask_price = $rows['ask_price']; } Let's say the array is 50.50, 40.50, 35.00 I need some code to do: 100.00 - 50.50 = 49.50 49.50 - 40.50 = 9.00 9.00 - 35.00 = <0 does not do anything so remainder = 9.00 would it be something like Code: [Select] $new_ask_shares = $_POST['ask_shares']; //some sort of a loop or array or combo of both ($new_ask_shares - $ask_price); the numbers are just an example as the actual numbers will be different each time I query my DB. Thanks in advance what Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. I have 2 queries that I want to join together to make one row
$sql = "SELECT * from updates ORDER BY id DESC LIMIT 3"; $stmt = $link->prepare($sql); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows = '0') { echo "There haven't been any updates yet."; } else { echo "There are news posts"; }
Gives me the error "Cannot write property in /home/evoarena/public_html/Dev/news.php:14 ", line 14 is the if statement. How can I fix it? Hi, im creating a script for a website that will list products, i have the basic construct which lists the products from the database but it lists then vertically, i have set the width of each 'product' to 200px so i could have around 3 colums and many rows. can anybody advise how i would make them run horizontally aswell as vertically? my code below: <?php include_once("include/globals.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <?php //Get database Results $result = mysql_query("SELECT * FROM Products WHERE is_active = 1") or die(mysql_error()); //keeps getting the next row until no more records while($row = mysql_fetch_array($result)) { //echo results ($result) echo '<div id="holder">'; echo '<div class="title">' . $row['Name'] . '</div>'; //insert image here echo '<div class="image">'; echo '<a href="product_detail.php?id="><img src="' . $row['image'] . '" width="100" alt="" border="0"></a>'; echo '</div>'; echo '<div class="tag_line">'; echo $row['Tag_Line']; echo '</div>'; echo '<div class="price">Now Only: £'; echo $row['Website_Price']; echo '</div>'; echo '<div class="prod-footer">'; echo "<a href=\"product_detail.php?id={$row['ID']}\"> more info </a></li>"; echo '</div>'; echo '</div>'; } ?> </div> </body> </html> im wondering how to get php to read the latest row (instead of show them all) and when another one comes it replaces it once the page refreshes Hi ,im face little problem in duplicating rows. it's not easy task wht i need: i got this rows right now id----------position-------------A_Q_ID 1---------------1--------------------5----- 2---------------2--------------------5----- 3---------------3--------------------5----- 4---------------1--------------------6----- 5---------------2--------------------6----- 6---------------3--------------------6----- what i need is to duplicat all the rows and have them inserted after the rows i allready have like that: id------------position-------------A_Q_ID 7-----------------1--------------------7----- 8-----------------2--------------------7----- 9-----------------3--------------------7----- 10---------------1--------------------8----- 11---------------2--------------------8----- 12---------------3--------------------8----- i tryed few ways without success . any idea how to do that please? i cannot get the logic on doing it thanks Can any one tell me whats the best ( actually error free ) which i can use to count the number of rows finally resulting after select command. I use this ... Code: [Select] $sql = mysql_query("select * from usname where name1='$name1' and name2='$name2' and amm='$amm'"); $num=mysql_num_rows($sql); echo $num; But it always gives the same error.... and the error is.......... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\insert.php on line 20 where line 20 is... Code: [Select] $num=mysql_num_rows($sql); - Pranshu Agrawal pranshu.a.11@gmail.com Hi guys, I want to count the number of rows in a table and want to display them. However that field stays empty. Everythign else works. What do I do wrong? Code: [Select] <?php //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="25" align="center"><span class="style2">No.</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="342" align="center"><span class="style2">school</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['num_rows']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> Hi guys I have a problem. I limit the displayed rows by 10 (which works) and then a link saying "next" or "previous" The link itself works, but the site always just displays teh first 10 data entries. What do I do wrong? Thank you! Code: [Select] <?php $host="****"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id ORDER BY school_name LIMIT 0, 10"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <?PHP //check if the starting row variable was passed in the URL or not if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { //we give the value of the starting row to 0 because nothing was found in URL $startrow = 0; //otherwise we take the value from the URL } else { $startrow = (int)$_GET['startrow']; } ?> <?PHP //this part goes after the checking of the $_GET var $fetch = mysql_query("SELECT * FROM sp_users,sp_schools where sp_users.user_id=sp_schools.school_id LIMIT $startrow, 10")or die(mysql_error()); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } #Layer1 { position:absolute; left:803px; top:36px; width:65px; height:28px; z-index:1; } #Layer2 { position:absolute; left:707px; top:19px; width:143px; height:39px; z-index:1; } #Layer3 { position:absolute; left:247px; top:463px; width:175px; height:53px; z-index:2; } --> </style> <title>User overview</title> </html> <div id="Layer2"> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="foo" value="<?= $foo ?>" /> <input type="submit" name="submit" value="Refresh" /> </form></div> <div id="Layer3"><?PHP //now this is the link.. echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>'; ?> <?PHP $prev = $startrow - 10; //only print a "Previous" link if a "Next" was clicked if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>'; ?></div> <table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users / Total: <?php echo $num_rows ?></strong></div></td> </tr> <tr> <td width="342" align="center"><span class="style2">school</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> " SELECT event.*, epr1.participantId AS team_1, epr1.participantRoleId AS team_1_role, epr2.participantId AS team_2, epr2.participantRoleId AS team_2_role FROM bb_EventParticipantRelation epr1, bb_EventParticipantRelation epr2, bb_Event event WHERE event.parentId='".$leage_type."' AND epr1.id != epr2.id AND epr1.parentParticipantId = '0' AND epr2.parentParticipantId = '0' AND epr1.eventId=event.id AND epr2.eventId=event.id ORDER BY epr1.participantRoleId ASC, event.startTime, team_1, team_2 ASC " This sql gets 2 rows and combines them as one, it does work but the issue is it seems to be taking too long in loading the page also I just need some advice on a better version Thank you Hi ive got this code which echos out all the rows from an SQL table. while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['subject1'] . "</td>"; echo "<td>" . $row['subject2'] . "</td>"; echo "<td>" . $row['subject3'] . "</td>"; echo "<td>" . $row['subject4'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "</tr>"; } echo "</table>"; All i want to do is add all the 4 subject together and echo it out. simple but not sure how to do it. any ideas please? Thanks Matt ...I'm Australian, hence the 'u' in coloured, in case you're wondering! Basically I'd like to create a table of results for a running race that has rows shaded pink if the participant is female. I think my problem is something to do with not declaring 'sex' as a variable, but I'm not really sure how to do this. My code is below. Any advice would be much appreciated. Code: [Select] <?php $dbcnx = @mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('coast2ko_test')) { exit('<p>Unable to locate the results ' . 'database at this time.</p>'); } $sql = mysql_query("SELECT * FROM result_single ORDER BY place ASC"); echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>"; echo "<tr> <td><H3>First name</h3></td> <td><H3>Lastname</H3></td> <td><H3>Sex</H3></td> <td><H3>Time</H3></td><td><H3>Place</H3></td></tr>"; // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($sql)) { // Print out the contents of each row into a table if ($sex=="F") echo "<tr bgcolor='#FF99FF'>"; else echo "<tr>"; echo "<tr bgcolor='#FF99FF'>"; echo "<td>"; echo $row['firstname']; echo "</td><td>"; echo $row['lastname']; echo "</td><td>"; echo $row['sex']; echo "</td><td>"; echo $row['time']; echo "</td><td>"; echo $row['place']; echo "</td></tr>"; } echo "</table>"; ?> Hi, having stopped php for a while, i'm a little rusty, can someone help me - instead of the results returning in a row by row format, can i have it so it returns column by column? so, rather than result 1 being first, then 2 underneath then 3 etc etc, can i have result 2 next to result 1? heres my code $result = mysql_query("SELECT * FROM members ORDER BY member_id DESC") or die(mysql_error()); echo "<table border='2'>"; echo "<tr> <th></th> <th></th> <th></th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row[printf('<img src="%s" height="96" width="128" style="border: 0" />', $row['profile_pic_short'])]; echo "</td><td>"; echo "<a href=\"PHP-Login/advert_pages/view_profile_specific.php?seller_name=$row[login]\">". $row['login'] . "</a>"; echo "</td></tr>"; } echo "</table>"; ?> all help appreciated thanks I Have a page that will display the data that was posted into a database, but it displays it like this: id logoname locationname address city state zip phone website etc... I want to display the data like this: id <--- this will repeat records 4 columns across logoname locationname etc... id <--- this will repeat records 4 columns across logoname locationname etc... and then repeat similar for the rest of the data. Sorry Im a n00b, but trying. Here is the current code: <?php include "config.php"; $con = mysql_connect("$dbhost","$dbusr","$dbpass"); if (!$con) { die('Could not connect:'. mysql_error()); } mysql_select_db("$dbname",$con); $q="select * from venues"; $result=mysql_query($q); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<table border='0'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td></td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> Help would be greatly appreciated and an explanation so that I don't have to keep asking can someone please give me some guidance on how to do this please I am wanting to create a status updating type application on my site and i have this idea in my head i want it to retrive and print the last 3 posts (max ids) made by the user if someone could give me some example code please and i can hopefully work from that. Thanks James |