PHP - Echo 1-10 In Table
Hi
I have written the below code to echo a table Code: [Select] <table> <?php //start top 10 loop $sql=mysql_query("SELECT * FROM Games ORDER BY up DESC LIMIT 10"); while($row=mysql_fetch_array($sql)) { $title=$row['gametitle']; $gameid=$row['gameid']; $up=$row['up']; ?> <tr><td><a href="Reviews.php?gameid=<?php echo $gameid ?>"><?php echo $title ?></a> <td align="right"><?php echo $up ?></td> </tr> <?php //end top 10 loop } ?> </table> I want to add a new column to the table that lists them as 1 through to ten. Can anybody advise the best way to do this? Thanks Similar Tutorialsfor some reason it will not render to the row... ive added the php echo to the row in question and it runs with the top row... can someone take a look and let me know what i am doing wrong... thanks trey here is the code... the php echo in bold red should show up on the next row; but, it doesnt... <?php /** * @version $Id: mod_gridiron_game_results.php, v1.5.0 March 2011 01:32:15 * @author Fastball Productions * @package Gridiron * @copyright Copyright (C) 2011 Fastball Productions * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ // no direct access defined('_JEXEC') or die('Restricted access'); $db =& JFactory::getDBO(); // get the module parameters $heading = $params->get( 'heading', '' ); $showpast = $params->get( 'showpast', '1' ); $numberpast = $params->get( 'numberpast', '1' ); $linkboxscore = $params->get( 'linkboxscore', '1' ); $shownextgame = $params->get( 'nextgame', '1' ); $numbernext = $params->get( 'numbernext', '1' ); $linknext = $params->get( 'linknext', '1' ); $seasonid = $params->get( 'seasonid', '1' ); $gametypes = $params->get( 'gametypes', '1' ); $teamids = $params->get( 'teamids', '' ); $leagueids = $params->get( 'leagueids', '' ); $divisionids = $params->get( 'divisionids', '' ); if (is_array($gametypes)) { $gametypes = implode(',', $gametypes); } if (is_array($teamids)) { $teamids = implode(',', $teamids); } if (is_array($leagueids)) { $leagueids = implode(',', $leagueids); } if (is_array($divisionids)) { $divisionids = implode(',', $divisionids); } // if there is a league configured, get the teams within the league/division; if ($teamids == '' && ($divisionids || $leagueids)) { if ($divisionids) { // get a listing of all team ID's that belong in the league and division; $sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(divisionid, '$divisionids'))"; } else { // get a listing of all team ID's that belong in the league; $sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(leagueid, '$leagueids'))"; } $db->setQuery($sql); $rows = $db->loadResultArray(); $teamids = implode(',', $rows); } else if ($teamids == '') { // get the default team (single team component only); $db->setQuery("SELECT id FROM #__gridiron_team WHERE (defaultteam = 1)"); $teamids = $db->loadResult(); } // get the last x number of games played and the results; $db->setQuery("SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid, DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate, DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime, h.name AS hometeam, v.name AS visitingteam, b.finalv, b.finalh FROM #__gridiron_schedule AS a LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id LEFT JOIN #__gridiron_boxscore AS b ON a.id = b.gameid WHERE (a.scored = 1 AND a.season = {$seasonid} AND (FIND_IN_SET(a.gametype, '$gametypes')) AND (FIND_IN_SET(a.hometeam, '$teamids') OR FIND_IN_SET(a.visitingteam, '$teamids')) AND a.gamedatetime < now()) GROUP BY a.id ORDER BY a.gamedatetime DESC LIMIT 0, {$numberpast}"); $pastgames = $db->loadObjectList(); // get the next x number of games scheduled; $db->setQuery("SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid, DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate, DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime, h.name AS hometeam, v.name AS visitingteam, t.description AS gametype FROM #__gridiron_schedule AS a LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id LEFT JOIN #__gridiron_gametype AS t ON a.gametype = t.id LEFT JOIN #__gridiron_location AS l ON a.location = l.id WHERE (a.scored = 0 AND a.season = {$seasonid} AND (FIND_IN_SET(a.gametype, '$gametypes')) AND (FIND_IN_SET(a.hometeam, '$teamids') OR FIND_IN_SET(a.visitingteam, '$teamids')) AND DATE_ADD(a.gamedatetime, INTERVAL 3 HOUR) > now()) GROUP BY a.id ORDER BY a.gamedatetime ASC LIMIT 0, {$numbernext}"); $nextgames = $db->loadObjectList(); ?> <table width="100%" border="0" align="center"> <?php if ($showpast && $numberpast > 0) { ?> <tr> <td colspan="2" style="text-align:center;"><b><?php echo $heading;?></b></td> </tr> <tr> <td width="43%"><b><u>Matchup</u></b></td> <td width="57%" style="text-align:center;"><b><u>Result</u></b></td> </tr> <?php foreach ($pastgames as $past) { ?> <tr> <td> <?php echo $past->visitingteam;?> vs.<br /><?php echo $past->hometeam;?> </td> <td style="text-align:center;"> <?php if ($linkboxscore) { ?> <a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=boxscore&id=$past->id");?>"><?php echo $past->finalv;?><br /><?php echo $past->finalh;?></a> <?php } else { ?> <?php echo $past->finalv;?><br /><?php echo $past->finalh;?> </td> <?php } ?> </tr> <tr> <td colspan="2"></td> </tr> <?php } ?> <?php } ?> <?php if ($shownextgame && $numbernext > 0 && $nextgames) { ?> <tr> <td colspan="2"><b><u>Next Game</u></b></td> </tr> <?php foreach ($nextgames as $next) { ?> <?php $next->visitingteam == '' ? $next->visitingteam = 'TBA':$next->visitingteam = $next->visitingteam;?> <?php $next->hometeam == '' ? $next->hometeam = 'TBA':$next->hometeam = $next->hometeam;?> <tr> <td colspan="2"> <?php if ($linknext) { ?> <?php if ($next->visitingteam == 'TBA') { ?> <?php echo $next->visitingteam;?> <?php } else { ?> <a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->visitingteamid");?>"><?php echo $next->visitingteam;?></a> <?php } ?> vs. <?php if ($next->hometeam == 'TBA') { ?> <?php echo $next->hometeam;?> <?php } else { ?> <a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->hometeamid");?>"><?php echo $next->hometeam;?></a> <?php } ?> <?php } else { ?> <?php echo $next->visitingteam;?> vs. <?php echo $next->hometeam;?> </td> </tr> <tr> <td colspan="2"><?php } ?><?php echo $next->gamedate . ' ' . $next->gametime;?> </td> </tr> <?php } ?> <?php } ?> </table> Hey all - What is the appropriate syntax to echo out each character name (vanity_name), and their total number of "ties" "wins" and "losses" Thanks for your help! $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; $mario_sql = mysql_query($q1); Code: [Select] <?php echo "Mario: " . $mario_sql; ?> Please help, when I run this search and enter something in the search thats not in the database, it doesnt reply with "Your query returned 0 results" as it should. I tjust stays blank Here's the section of code in question... if ($search) // perform search only if a string was entered. { mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); $srch="%".$search."%"; $query = "select * from tvads WHERE advert LIKE '$srch' ORDER BY advert, year DESC, details ASC LIMIT 0,30"; $result = mysql_db_query("cookuk_pn", $query); if ($result) { $count = 1; print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#0000FF\" width=\"900\">"; print "<tr><td width=\"200\" height=\"30\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Advert / Description</font></b></u></td>"; print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Year</font></b></u></td>"; print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Artist</font></b></u></td>"; print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Track</font></b></u></td>"; print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Buy Album</font></b></u></td>"; print "<td width=\"100\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Download MP3</font></b></u></td></tr>"; while ($row = mysql_fetch_array($result)) { // Begin while $data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['advert']. "</font><br>"; $data .= "<font face=\"arial\" size=\"1\" color=\"#000080\"><i>" .$row['details']. "</i></font></td>"; $data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['year']. "</font></td>"; $data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['artist']. "</font></td>"; $data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['track']. "</font></td>"; $data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['asin_ref']. "</font></td>"; $data .= "<td width=\"100\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['mp3_ref']. "</font></td></tr>"; $count++; } // end while $data .="</table>"; echo $data; } else { echo "problems...."; } } else { echo "Your query returned 0 Results"; } ?> This serves more or less a meaningless purpose for my testing, but I've been trying to echo out the names of the tables that are being used in my UPDATE and SELECT queries and I have yet found a way to do this.. Did some research on php.net and Google and did not find anything that seems to directly address this.. My guess is it's so stupid simple, I probably will have an answer by the time I wake up.. But id there are any suggestions on this, Id be glad to take. hello, im trying to add a hyperlink that launches in a new window to the following (in the last column) any ideas? Code: [Select] echo "<tr>"; echo "<td align='center'>" . $row["ID"] . "</td>"; echo "<td align='center'>" . $row["Name"] . "</td>"; echo "<td align='center'>" . $row["jobNO"] . "</td>"; echo "<td align='center'>" . $epn . "</td>"; echo "<td align='center'>" . $cname . "</td>"; echo "<td align='center'>" . $cadd . "</td>"; //want to add a hyperlink here echo "</tr>"; } echo "</table>"; } 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> 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']; ?> // Other code //echo "<table border='10' cellpadding='3' cellspacing='2'>"; This works echo "<table class="my-table">"; //This does not work echo "<tr><th>First Name</th><th>Last Name</th><th>Home Phone</th><th>Cell Phone</th><th>email</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['first']; echo "</td><td>"; echo $row['last']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['cell']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> Error message: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/bayare27/public_html/content/pages/display_all_members1.php on line 29 Line 29 is: echo "<table class="my-table">"; <table class="my-table">" is a valid statement because It works in another program, but html not php I actually asked a question here yesterday and decided to try a different route with it. What I am doing is passing an email variable entered from my home page on to www.dollapal.com/offerlist.php. I'm wanting this page to be a complete list of all of my entries in my surveys table. The email variable needs to be appended to the end of every link. I got that to work, but what I want to do now is display that information for every record in my 'surveys' table. Right now I am using the random function, which I'm sure is wrong, but I'm not sure what function to be looking for. Is it possible to use a foreach function here to echo each record? If so, I'm not sure how exactly to call the foreach() function in this case. I believe my two problems lie in the random and foreach functions, but I'm not sure how to correct them. I've attached a little chunk of code that I'm working with. I'm not sure if I'm completely off base here, or if I'm close to achieving my desired result. Please let me know if you require more information. This forum has been amazing to me so far. Thank you all for your help! Hi, I wonder if I somebody can help me I have three drop down lists which are populated from data thats stored in my sql database. I also have a table which is echoed from the database all on the same page. What i want to do is allow users to select values in the drop down lists which will then echo different results below in the table. Is this possible. So on page load it will show all of the info in the html table. Then when the user changes the drop downs and clicks submit it will change the query to something SELECT dropdown1 value FROM users where Dropdown2 = 1 AND Dropdown3 = 2 etc. Is this possible to display this information on the same page using the dropdown list or does it need to load a different page as the client side is trying to edit a server side script? If its possible please can someone give me an example. Thanks in advance Edd Hi 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 How do you do this? Thanks in advance. 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> OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Hi all, I have a page which simply pulls info from a database by id: <?php include ('connect.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM JOBS WHERE id=$id"); if (!$query) { echo "Could not run query: " . mysql_error(); exit; } $row = mysql_fetch_row($query); { echo "<body><h3>" . $row[1]. "</h3>"; echo "<h4>" . $row[2] . "</h4>"; echo "<h4>" . $row[3] . "</h4>"; echo "<h5>Duties & Responsibilities:</h5><ul>"; echo "<li><strong>" . $row[4] . "</strong>" . $row[5] . "</li>"; echo "<li><strong>" . $row[6] . "</strong>" . $row[7] . "</li>"; echo "<li><strong>" . $row[8] . "</strong>" . $row[9] . "</li>"; echo "<li><strong>" . $row[10] . "</strong>" . $row[11] . "</li>"; } ?> However in some cases the rows in the database may only contain data upto row 6 for example, how would I go about coding this so that it only displays rows that exist. If row 6 exists then 7 always will too as the information is connected. I am manually added this stuff into phpmyadmin as I do not need a form as once it is complete then it will not need to be added to. Also row 8 and 9 may contain data but 6 and 7 may not Many Thanks What is the correct way to write an if/else statement within an echo? I need to alter this so that I can query to see what data is found and if not correct not to echo the rest of the statement. Code: [Select] echo '<td class="productbox"> <h1>' . $product_title . '</h1> </td>'; So from the above code which is echoed within the single quotes, what is the correct way to include an if else check on a value from the database. I know how its done, but just want to save time and write it the correct way within this. |