PHP - Function Help -display Many Rows With Same Id-
Morning
I have a table with many rows. Some of these rows have the same id number. I'm wondering how I print all the rows with the like id like so programing,design,help. My fucntion is below. function getPostTags($postid){ $sql = mysql_query("SELECT tag FROM tags WHERE id=$postid") or die(mysql_error()); if (mysql_num_rows($e)){ extract(mysql_fetch_array($sql)); $tags[$postid]=array(); $tags[$postid]['tag']; } return $tags; } So if I do this <?php print $tags; ?> It only prints out one result from my table. What do I have to do it get it to print all row field values from the table with a comma. Right now the only way I can do this is instead of printing "$tags" (which only gives me one of the many values) I query the database again and do a while statement with $row = mysql_fetch_array. This isn't the right way to do it. Can someone help or give me some pointers? Thanks for the help. Similar TutorialsI have a mysql table that holds data for cars - each car has it's own ID, name, and year. Some cars are repeated. Example: (ID - year - car name) 0001 - 2009 - Honda Civic 0002 - 2008 - Toyota Prius 0003 - 2009 - Honda Civic 0004 - 2008 - Toyota Prius 0005 - 2008 - Toyota Prius 0006 - 2007 - Honda Civic How would I count how many of the same type of cars I have in that table and then display the quantity next to the car name? Like for the above example it would be: 2009 Honda Civic: 2 2007 Honda Civic: 1 2008 Toyota Prius: 3 Thanks in advance for any help :D <?php require_once('upper.php'); require_once('database.php'); if(isset($_COOKIE['LoginIdCookie'])) { echo '<h4>Welcome '.$_COOKIE['LoginIdCookie'].'</h4>'; } else{ echo '<h4>Events</h4>';} $result=mysqli_query($dbc,"select * from events") or die('Not Connected'); echo "<html> <body>"; echo "<form method='post' action='EventParticipator.php'>"; echo "<u><h4>Please tick events in which you want to participate</h4></u>"; /*echo "<table cellspacing='0' cellpadding='15'> <th><b>Event Title:</b></th> <th ><b>Event City:</b></th> <th><b>Content:</b></th> <th><b>Images:</b></th> <th><b>Event Date:</b></th>";*/ //while($row=mysqli_fetch_array($result)) $row=mysqli_fetch_array($result); for($i=0;$i<5;$i++) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<tr><td><img src='$Photo' width='120' height='90'/></td><td>$City</td><td>,</td><td>$Date</td><td>:</td><td>$Title</td></tr> <tr><td>$Content</td></tr> <tr><td><a href='#'>Know more</a></td><td>/</td><td><a href='#'>Click here to participate</a></td></tr>"; } //echo "<tr><td><input type='submit' name='submit' value='Participate'</td>"; if(isset($_COOKIE['LoginIdCookie'])) { echo "<td><a href='log_out.php'>Log out</a></td>"; echo "<td><a href='EditActivity.php'>Edit Your Activities</a></td></tr>"; } echo "</table></form></body></html>"; require_once('lower.php'); ?> Quote Hi friends .......... I write above code to display top 5 rows from the database but it not works properly. It displays first row 5 times which is undesireable. Anyone please help????????????????? thanks in advance.................. Hey guys! I've been having trouble with this all day. I'm wanting to display my results in rows. Like, 4 results in 1 row, then another 4, then another 4, etc. like this: IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE I'm nto sure how to do that. I want to display pictures. Here is my code for the page: bag.php: 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 "<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><content><center><font size=6>Inventory</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Inventory</font><br><br>"; $action = $_GET['action']; $gid = $_GET['itemid']; $irow = "SELECT * FROM uitems WHERE username='$showusername'"; $iquery = mysql_query($irow); while($ir = mysql_fetch_array($iquery)) { $uid = $ir['uitemid']; $iid = $ir['theitemid']; $iun = $r['username']; $il = $ir['location']; $tirow = "SELECT * FROM items WHERE itemid='$iid'"; $tiquery = mysql_query($tirow); while($tir = mysql_fetch_array($tiquery)) { $tiid = $tir['itemid']; $tin = $tir['name']; $tiim = $tir['image']; $tid = $tir['description']; $tirr = $tir['rarity']; $tit = $tir['type']; $tiu = $tir['uses']; $tis = $tir['strength']; $tide = $tir['defense']; $tih = $tir['heals']; echo "<img src=/images/items/$tiim><br>$tin<br><br>"; } } } ?> </html>I have no errors, everything works great! It's just I'm not sure how to display them the way I want them. Right now they are displayed like this: IMAGE IMAGE IMAGE IMAGE Any help is greatly appreciated, thank you! I can't seem to get the math right! I have a function, pulling 13 states (canadian provinces) from the database and I can't seem to get them all to show in 5 columns. Where am I doing this wrong. The code below only shows 7 of 13... I just can't seem to get where I am off! PHP CODE: function map_showCA() { global $db, $tpl; // ShowLocalResources $sSQL = "SELECT * FROM states_canada ORDER BY state;"; $db->query($sSQL); $next_record = $db->next_record(); while ($next_record) { $state_id = $db->f("id"); $state = $db->f("state"); $statename = $db->f("statename"); $statename_html = $db->f("statename_html"); $next_record = $db->next_record(); if (!USE_SEO_LINKS) { $statename_html = $state_id; } $vendors_states[] = array("name" => $statename, "id" => $state_id, "state_html" => $statename_html); } $vendors_states_col = array_chunk($vendors_states, 5, true); $loop = (int)(count($vendors_states) / 5); if(count($vendors_states) % 5 > 0) $loop++; $j = 0; for($i = 0; $i < $loop; $i++) { $parameters = 'http://'.$vendors_states_col[0][$j]["state_html"].'.ilocalize.com'; // $first_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("first_column_link", $parameters); $tpl->set_var("first_column", tohtml($vendors_states_col[0][$j]["name"])); $parameters = 'http://'.$vendors_states_col[1][$j+6]["state_html"].'.ilocalize.com'; // $second_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("second_column_link", $parameters); $tpl->set_var("second_column", tohtml($vendors_states_col[1][$j+6]["name"])); $parameters = 'http://'.$vendors_states_col[2][$j+12]["state_html"].'.ilocalize.com'; // $threeth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("threeth_column_link", $parameters); $tpl->set_var("threeth_column", tohtml($vendors_states_col[2][$j+12]["name"])); $parameters = 'http://'.$vendors_states_col[3][$j+18]["state_html"].'.ilocalize.com'; // $fourth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fourth_column_link", $parameters); $tpl->set_var("fourth_column", tohtml($vendors_states_col[3][$j+18]["name"])); $parameters = 'http://'.$vendors_states_col[4][$j+24]["state_html"].'.ilocalize.com'; // $fifth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fifth_column_link", $parameters); $tpl->set_var("fifth_column", tohtml($vendors_states_col[4][$j+24]["name"])); $tpl->parse("ShowLocalResourcesCA", true); $j++; } } HTML CODE: Code: [Select] <table border="0" cellpadding="1" cellspacing="1" class="description_text2" style="padding-bottom:6px;" width="100%" id="dashed_box_gray"> <!--BeginShowLocalResourcesCA--> <tr> <td width="110" align="left" style="padding-left:6px; padding:6px;"><a href="{first_column_link}" class="user_blue_14px">{first_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{second_column_link}" class="user_blue_14px">{second_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{threeth_column_link}" class="user_blue_14px">{threeth_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{fourth_column_link}" class="user_blue_14px">{fourth_column}</a></td> <td width="108" align="left" style="padding-right:6px; padding:6px;"><a href="{fifth_column_link}" class="user_blue_14px">{fifth_column}</a></td> </tr> <!--EndShowLocalResourcesCA--> </table> i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks Hi Guys! Trying to display data in 3 rows horizontally and 25 vertiacally Code: [Select] // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(biddersId)'] ." bidders logged."; echo "<br />"; } $query = "SELECT * FROM bidders ORDER BY biddersId"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Bidders</th>"; // 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"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</br>"; echo "</td><td>"; } echo "</table>"; ?> I've got my code working OK in that the correct results are drawn from the database. What I have here in the code is an array consisting of an image, accompanied by its title and thirdly a link to activate a quiz associated with the image. Everything works fine, except because the page is dynamic, I always have an unknown number of sets of data (image, title and link) which I want to display so that each set of data takes up a new row. The code I have here, while displaying the correct data, places all of the results into the same row. Any suggestions are most welcome. Code: [Select] <?php // Query the database $query1 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query2 = mysql_query("SELECT url_small FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query3 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); while($row1 = mysql_fetch_array($query3)) { $linkname .= $row1['title']."<br />\n"; } ?> <table> <tr> <td> <?php while ($row2 = mysql_fetch_array($query2)) { $thumbnail.= $row2['url_small']; echo "<img src='wood_tool_images/{$row2['url_small']}' alt='' /><br />\n"; } ?> </td> <td height="200"> <?php echo $linkname ?> </td> <td> <?php while ($row1 = mysql_fetch_array($query1)) { $quizname.= $row1['title']; echo "<a href='../{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; } ?> </td> </tr> </table> Hi, I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine. What I want to do is to have a piece of text that reads: (insert pre release amount of signer upperers here) have signed up. Will you? I'm guessing that the amount of rows on the table, would end up being the number. How do I do this? Thanks, Jack Hi, I'm trying to build a 'simple' page to improve a process where I work.
I'm wanting to do this.
Read either the last line, the last 10 lines, or something I decide on from a log and display the output in table rows and columns.
I've done this before with loops and db query's, but don't know how to approach it using php only as this is the first time I'm using it.
So right now I have this in a table but it will only display one row.
<tr><td colspan="5"> i have 8 division (div), i want to display 4 rows in 4 division and the remain 4 rows in the next 4 division here is my code structure for carousel
<div class="nyie-outer"> second row third row
fourth row fifth row sixth row seven throw eighth row
</div><!--/.second four rows here-->
sql code
CREATE TABLE product( php code
<?php how can i echo that result in those rows
Heres what i got... function printLB1 (){ $result = mysql_query("SELECT * FROM leaderboards ORDER BY CollegeFootballPoints DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->Username; $leaderboardPoints[] = $row->CollegeFootballPoints; } $num = mysql_num_rows($reault); //I know from here to ................... needs to be in a var or echo or something. <tr> <td>1.</td> //This will auto increment too like i++ but i cna do that myself! <td>echo $leaderboard;</td> <td>echo $leaderboardPoints;</td> </tr> //Here......................................................... } I need to pull a table row per user. But i want to somehow do it once in a function and then ill echo the function into a table after the php stuff is done. Like i want to pull every a table row per user in the function. then display the function below that way i don't have to write a whole extra query and table row per person. If you understand please help if not please let me know where i can explain more. Thanks I am displaying rows from a database onto a page using: while($row=mysql_fetch_array($query)){ echo $row['name']; } I need to figure out how to limit the rows shown to the page to 100. And if there are 100 rows on the page, a link will be displayed at the bottom, that says "Next 100". Then this will display the next 100 rows. Can you give an example how to do this please? Thanks This is the php code i have wrote but i need some help....as this code is displaying my value from database when time(which is saved in database too) is equal to current server time. let say e.g : time saved in database is 6:00:00, so when current time is equal to database time which is 6:00:00 it then display my stored value(e.g 40 (int) ) from database. which is : 40 so i need help out here when the value shows : 40 on exact 6:00:00 (time) but disappear after a second i want to be display this value for 30 more sec.after that a new value from database will come and diplay as the time goes to 6:00:30 hope friend you will help me out soon thank you below is the code of php file. // First Connect to database echo "<meta http-equiv='refresh' content='20'>"; $link = mysql_connect("$dbhost","$dbuser","$dbpass") or die(mysql_error()); // Connection starts here mysql_select_db("$dbname") or die(mysql_error()); $sql = "SELECT * FROM datatable WHERE time = '$ctime' "; // simple sql example echo $cdate; echo "<br>"; echo $ctime; $re = mysql_query($sql) or die(mysql_error()); // Here's where you'll get an error if the SQL is invalid. while($row = mysql_fetch_array($re)) { // Beganing 1 include("variables.php"); echo "<br>"; echo $row['value']; // value to be displayed for 30Sec after displayed on site. } //Closing 4 mysql_close($link); // code ends here..:-) 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. Hello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible. I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. 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? Hello all, I have some piece of code that is nested like this $variable = 'This is a global argument'; function parentFunction($variable) { function childFunction() { echo 'Argument of the parent function is '.$GLOBALS['variable']; } childFunction(); } parentFunction(5); What I want to know is - Is there a way to access a variable from the parent function without passing arguments to the child function? (Something like how classes have parent::?). I don't want to use $GLOBALS because it might cause some variable collision, and I didn't want to pass arguments because incase I decide to change the arguments in the parent function I'd have to do it in the child function aswell. From my searching around in the Internet it seems like this is not possible, but if theres a slight chance that there might be something out there, i'm willing to give it a shot . Thanks in advance 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 Hello I have a table that inserts a new row with data when a member views a page. I wish to count all the rows for each member, and then be able to show what the cuurent members "position" is eg. what members has the highest row count. Example. counting the rows for member_A returns 1000 rows, the number of rows for member_B returns 1500 rows. How can I display for member_A that he is in "second" place? |