PHP - Displaying Row If Listing Exists On Different Table
Hey, I am still learning PHP and all it's functions. So some of the coding may not be clean. But here is the script I made that I am having problems with:
Code: [Select] <?php // Adjust MySQL connection settings... $username="newestfu_Dan"; $password = "camaro"; $hostname = "localhost"; $database = "newestfu_wowtrader"; // Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); // Run our query, see if session username exists in session field... $sql="select username,email from user where username='{$_SESSION['user']}' limit 1"; $result=mysql_query($sql,$conn); // Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result); // If one row was found in the result set, username exists... if (mysql_num_rows($result)==1) { print "Welcome, {$data['username']}, your current email on file is: {$data['email']}"; echo "<br />"; $query="select seller,id,title from listings"; $queryresult=mysql_query($query,$conn); $info=mysql_fetch_assoc($queryresult); if ( $info['seller'] == $data['username'] ) { echo "{$info['title']}"; } else { echo "You have no current auctions"; } // Otherwise... } else { print "Sorry, the username {$_SESSION['username']} was not found in our database..."; } ?> </body> </html> There are two queries going on. The first selects from the table "user" and gets the username depending on the user session and email. If one exists, it will go onto the next query to select from the table "listings" and gets seller, title, and id. It will then check if the username is equal to the seller. If it is, it will display the title. If not it displays otherwise. The problem is if the user has more than one title listed. But only 1 shows up. I'm guessing the line that has to change is Code: [Select] echo "{$info['title']}";But I'm not to sure on what to change it to. Thanks all for your help! Similar TutorialsRight, it's hard to explain, but I'll try my best. Litterally, I have a 'tab' box on my homepage. And a table called 'news'. Now, the table has the rows "shorttitle" "shortstory" and "image" in it. I want the title the three latest titles to be on the three tabs, and the story and image in the respective content areas. (The table auto increments the ID, and so order by ID descending limit of 3 yes?) Now, the code for the tabs is: Code: [Select] <?php $query = "SELECT * FROM news where published = '1' ORDER by id DESC LIMIT 3"; $row_news = mysql_fetch_array($query); ?> <div id="myTabs"> <ul> <li><a href="#firsttab"></a><? echo $row_news['shorttitle']; ?></li> <li><a href="#secondtab">newsID2</a></li> <li id="last"><a href="#thirdtab">newsID3 </a></li> </ul> <div id="firsttab" class="tab_content"> <div class="rafat"> <img src="<? echo $row_news['image']; ?>" /> <p> <? echo $row_news['shortstory']; ?> </p> </div> </div> <div id="secondtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE2" /> <p> newsSTORY2 </p> </div> </div> <div id="thirdtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE3" /> <p> newsSTORY3 </p> </div> </div> </div> Now, i've filled in the first tab with the MYSQL queries, but i'm unsure how to fill in the other two, because of the way it's coded.. I can't do a 'repeating' code, because of the IDs of the divs, and the three tabs are bunched together.. Anyone any ideas? Much apreciated. Thanks Luke Hi I have used TCPDF to generate documents with single values from a mysql table. Now I want to generate a calendar. I have a table events_pbw which contains (amongst others) the fields id, date and name. I would like to generate a pdf which lists all of the results for entries after a particular date (eg Jan 1st) I have this: // get data from events_pbw table $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE `date` > 2011-01-01" "); while($row = mysql_fetch_array($result)) { $appid = $row['id']; $date = $row['date']; $name = $row['name']; } But I don't know how to get the full list of results into the pdf. I'm sure this is very easy but I'm not great on php coding! Does anyone have any examples or help they could give me? Many thanks Hi all, I have a MySQL table with the field 'number'. When I SELECT * from that field, I get a return for the rows of 'number' in the order 1, 2, 3, 4, etc... SELECT * FROM products;Is there a way where I can get a return in the reverse order, so highest to lowest (4, 3, 2, 1, etc...)? Edited by Phaelon, 13 May 2014 - 03:23 AM. Hi, I am creating a temporary table. I need to check if the table already exists or not. If exists, I have to use the existing data else have to create a new temporary table. I can use 'Create If Not Exists'. How practical is this query? any issues with the performance? If the table exists it will be a huge data, I don't want to loose that data because recreating is an un-necessary load on the database. Hi, I just want to know how to check if a row/record already exists for a given table, but this code gives me message in browser: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in myTest.php This is the the snippet I am running: Code: [Select] <?php $connxn=mysql_connect("localhost","root"); $db=mysql_select_db("siliconvalley"); $toyNodePath="#document/siliconValleyHELLO"; $queryA=mysql_query("SElECT FROM pathexpress (path_express) WHERE path_express='$toyNodePath'");//make sure AT MOST ONE ROW EXISTS!! if(mysql_num_rows($queryA)==1) print "ALREADY IN table pathexpress!"; else { mysql_query("INSERT INTO pathexpress (path_express) VALUES ('$toyNodePath')"); print "ADDED $toyNodePath to table pathexpress!"; } ?> Please, any help is greatly appreciated! Say you have three tables like this...
STUDENTS (studentid, name)
CLASSES (studentid, classname)
GRADES (studentid, grade)
And not all students have grades yet. If you're doing a mysql query like below, is there anything you can add to the statement to check if a grade exists for each student? So that if while lopping through the results of the main query, I can easily do something with the students who don't yet have a grade yet (like maybe mark their names in red).
I can do this by putting a whole separate mysql query inside the looping of the main query, but that seems terribly inefficient to call the database again for EVERY student.
$sql = "SELECT * FROM students, classes, grades WHERE students.studentid = classes.studentid ORDER BY students.lastname"; $info= mysqli_query($connection, $sql); if (!$info) { die("Database query failed: " . mysqli_error()); } else { //code }Thanks! Greg Hi, I'm making a website that uses data stored in SQL. One of my pages allows the user to enter a new product into a product table. I was wondering if somebody could help me with some validation or Query that will not allow the user to enter a product name that already exists in the table? Code: [Select] $nameNew = $_POST['new]; $nameID = $_POST['newID]; $namePrice = $_POST['newPrice]; INSERT INTO products VALUES ($nameNew, $newID, $newPrice) $describeQuery = "SELECT ID, Name, Price FROM Products"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Price</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Name'].'</td>'; echo '<td>' .$row['ID'].'</td>'; echo '<td>' .$row['Price'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Thanks hi guys I am having trouble displaying a table in a mySQL database i get the error message Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/students/accounts/s7188633/hit3323/www/htdocs/Assiment2V2/main.php on line 47 Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/students/accounts/s7188633/hit3323/www/htdocs/Assiment2V2/main.php on line 53 these are the two line that it realtes to row 47: $Row = mysqli_fetch_row($result); row 53: $Row = mysqli_fetch_row($result); below is all the code if you wanted to look at it, thanks <?php $choice = addslashes ($_POST["selection"]); { $DBConnect = @mysqli_connect("neptune.it.swin.edu.au", "*****", "***") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "*****_db"; if (!@mysqli_select_db($DBConnect, $DBName)) echo "<p>The database is not available.</p>"; $SQLstring = "SELECT * FROM Books";// WHERE category = 'Programing'"; $QueryResult = @mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $NumRows = mysqli_num_rows($QueryResult); if ($NumRows == 0) echo "<p>No records returned.</p>"; else { mysqli_select_db($DBConnect, $DBName); $SQLstring = "SELECT * FROM Books"; $result = @mysql_query($DBConnect, $SQLstring); $Row = mysqli_fetch_row($result); do { echo "<tr><td>{$Row[0]}</td>"; echo "<td>{$Row[1]}</td>"; echo "<td align='right'>{$Row[2]}</td>"; echo "<td align='right'>{$Row[3]}</td></tr>"; $Row = mysqli_fetch_row($result); } while ($Row); } } mysqli_close($DBConnect); ?> Hi all! I've been recently messing with PHP and MySQL to attempt to create a search function for my tables (too advanced, so I toned it down to learning to just display data from my table). Anyways, I'm watching a YouTube video on how to do it, and I'm copying his code exactly, but I'm still getting an error. Can anyone help? Thanks. Edit: Sorry, my error was snuggled down below the code. Anyways, my error is just my while echo appearing in and out of my tables on the page. My code: <?php //Make connection mysql_connect('localhost', 'root', 'test'); // select db mysql_select_db('testdatabase'); $sql="SELECT * FROM employees"; $records=mysql_query($sql); ?> <html> <head> <title>Employee Data</title> </head> <body> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>ID</th> <th>First name</th> <th>Surname</th> <th>Age</th> </tr> <?php while($employees=mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$Employee['ID']."</td>"; echo "<td>".$Employee['First name']."</td>"; echo "<td>".$Employee['Surname']."</td>"; echo "<td>".$Employee['Age']."</td>"; echo "</tr>"; } // end while ?> </table> </body> </html> Edited by thwikehu1990, 19 January 2015 - 01:33 PM. Greetings,
My current code logs into a database, opens a table named randomproverb, randomly selects 1 proverb phrase, and then SHOULD display the proverb in the footer of my web page.
As of right now, the best I can do is get it to display "Array", but not the text proverb... this code below actually causes my whole footer to not even show up.
Please help!
<?php include("inc_connect.php"); //Connects to the database, does work properly, already tested $Proverb = "randomproverb"; $SQLproverb = "SELECT * FROM $Proverb ORDER BY RAND() LIMIT 1"; $QueryResult = @mysql_query($SQLproverb, $DBConnect); while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) { echo "<p style = 'text-align:center'>" . {$Row[proverb]} . "</p>\n"; } $SQLString = "UPDATE randomproverb SET display_count = display_count + 1 WHERE proverb = $QueryResult[]"; $QueryResult = @mysql_query($SQLstring, $DBConnect); ... ?> for 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> I have a field in my table that gets populated with a custom value from a subscription form, but when the data gets inserted into the table, it adds some text I do not want to output. The field is for the user's name, but when the form saves it, it saves the name, plus the text #2# (this is from a Wordpress plugin and I can't figure out how to remove the #2# when I insert the value there either). Is there a way to remove this #2# text when I display the field's value in MySQL and PHP? Now I am trying to display the images from my table and I have almost got it working, except for one small thing --- it seems to be displaying all the records, but instead of displaying the right image for each record, it's displaying the same image across all the records. Can anyone tell me what I have done wrong? Code: [Select] this is the gallery <?php $dbhost = 'localhost'; $dbuser = 'webdes17_lizkula'; $dbpass = 'minimoon'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'webdes17_jewelry'; mysql_select_db($dbname); $all_records = "SELECT * FROM gallery"; $all_records_res = mysql_query($all_records); $image = mysql_result($all_records_res, 0, 'image'); while($nt=mysql_fetch_array($all_records_res)){ echo "<img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/$image>"; } ?> I'm guessing I have the $image variable in the wrong place, but when I tried placing it within the while statement, the page never loaded, and instead acted like it was loading forever. What am I doing wrong? Here is the link to the page so you can see what is happening: http://webdesignsbyliz.com/wdbl_wordpress/test-submit/ I just can't get anything right today! Now I am trying to have a list of images, and when the user clicks on the image, the next page will display the image along with other fields for that record. I am sending the id through the hyperlink to the next page, and I have echoed it to ensure it's comign through, but I cannot get anythign to display ont he next page. What am I doin wrong? Here is the link to the page. If you click on one of the images, you 'll see that the next page is empty: http://webdesignsbyliz.com/wdbl_wordpress/test-submit/ Here is my code: Code: [Select] this is the gallery <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'jewelry'; mysql_select_db($dbname); $all_records = "SELECT * FROM gallery"; $all_records_res = mysql_query($all_records); $image = mysql_result($all_records_res, 0, 'image'); $id = mysql_result($all_records_res, 0, 'id'); while($nt=mysql_fetch_array($all_records_res)){ echo "<a href=http://webdesignsbyliz.com/wdbl_wordpress/test-display/?id=" .$nt['id']." ><img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/".$nt['image']." width=133 height=86></a>"; } ?> display page: Code: [Select] <?php $id = $_GET['id']; $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'jewelry'; mysql_select_db($dbname); $all_records = "SELECT * FROM gallery WHERE id = $_GET[id]"; $all_records_res = mysql_query($all_records); $image = mysql_result($all_records_res, 0, 'image'); $id = mysql_result($all_records_res, 0, 'id'); while($nt=mysql_fetch_array($all_records_res)){ echo "<img src=http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/".$nt['image']." width=133 height=86></a>"; } ?> What an I doing wrong this time?? :-( Hello,
I'm not sure if I'm allowed to post the code, as I didn't write it. But, if you could offer some ideas on where I'm going wrong, I'd be very appreciative!
I basically have a feature on my homepage that displays "Hello _username_!" upon login, but the username is missing. So, I'm presuming that the functionality for pulling the username from the table is somehow failing.
Any ideas?
Thanks
Daisy
I want to display my pictures I stored in Mysql in a 4 column, 2 row table WITH pagination. Here's the code I use to display the data currently: Code: [Select] //your username $username = "username"; //your password $password = "password"; //your mySQL server $host = "host"; //The name of the database your table is in $database = "database"; //connect, but if there is a problem, display an error message telling why there is a problem $conn = mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error()); //Choose the database from your mySQL server, but if there is a problem, display an error telling why $db = mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error()); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM myphotos"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 4; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM myphotos ORDER BY id ASC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a></span> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous</a></span> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <span class=\"paginationDown\"><b>$x</b></span> "; // if not current page... } else { // make it a link echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></span> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a></span> "; // echo forward link for lastpage echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Last</a></span><br> "; } // end if /****** end build pagination links ******/ // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { extract ($list); // echo data $url = $list['url'];; $title = $list['title']; $description = $list['description']; echo("$title<br><a rel=\"example_group\" title=\"$description\" href=\"$url\"><img src=\"$url\" alt=\"\" width=\"\" height=\"\" class=\"gallery_images\" /></a>"); } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a></span> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous</a></span> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <span class=\"paginationDown\"><b>$x</b></span> "; // if not current page... } else { // make it a link echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></span> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a></span> "; // echo forward link for lastpage echo " <span class=\"pagination\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Last</a></span><br>"; } // end if /****** end build pagination links ******/ The above code just displays the pictures vertically. Here's this code live: http://www.djsmiley.net/gallery/albums/my_photos.php (you can't view the page in IE) Now how would I make it so that the first 8 images in the database display in a 4x2 table, etc.? I have two tables categories and subcategories and what I want do is display them but here I ran into problem displaying the subcategories. Here's the code that doesn't work, all it does it displays categories. $query = "SELECT ID,name FROM `categores`"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['name']; $id_main=$row['ID']; $query2 ="SELECT name_subcategory FROM subcategories WHERE id_main_category=".$row['ID']; $result2 = mysql_query($query2) or die(mysql_error()); while ($row2=mysql_fetch_array($result2)); { echo $row2['name_subcategory']; } echo "<br />"; } Display should be -category --subcategory --subcategory -another category --subcategory of "another category" . . . I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM ESSAY_QUESTIONS WHERE SUBJECT = 'ENGLISH'") or die(mysql_error()); while($essay_data=mysql_fetch_array($result)){ $question = $essay_data['QUESTION']; $id = $essay_data['ID']; echo "<a href=\"englishessays.php?id=$id>"; echo "$question </a>"; echo "<br><br>"; } It seems to be almost working but it just displays one link and the address is all the rest of the code including </a>"; echo "<br><br>"; and other questions. I presume there's an error with how I've written the echo statements so can anyone see it? Or can anyone suggest a better way to do this? On the next page, the php will read the ID from the address and display the information form that record. Hi, I am trying to array a mysql tables data into a php table. Not having luck... <?php include('dbconnect.php') ?> <?php // Make a MySQL Connection $query = "SELECT * FROM cars"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['CarName']. " - ". $row['CarTitle']; echo "<br />"; echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100%>"; echo "<TR />"; echo "<TD />"; echo $row['CarName'].; echo "</TD>"; echo "<TD />"; echo $row['CarTitle'].; echo "</TD>"; echo "</TR>"; echo "</TABLE>"; } ?> Error says: Parse error: syntax error, unexpected ';' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/viewcars.php on line 69 echo </TD /> is line 69. Please help Ian hi, I am displaying mysql data in a table form using php. The first attached pic shows how is it looking with the current code. As you can see there are heading on the left and top of the table. So user can make booking on a specific day (heading is on the top for days) and for specific duration of time(headings are on the left). As in first pic, there has been a booking on Wed at 10 o clock, but the problem is, it is displaying duration just for half an hour. As this duration is from 10 o clock to 11 o clock. So what I want to do is in the second pic. Please view the second pic. In the second pic I want to display the highlighted area in blie because all this time is booked or reserved. Here is my current code. Code: [Select] <?php require("dbconnect/dbconnect.php"); $building = $_POST['building']; $block = $_POST['block']; $d_m = $_POST['d_m']; $choose_one = $_POST['choose_one']; function get_data($table, $choose_one) { $bool = 1; $get_days = mysql_query("SELECT * FROM days"); $get_times = mysql_query("SELECT * FROM time"); $days = mysql_num_rows($get_days); //$row_day_id = mysql_fetch_assoc($get_days); //$day_id_db = $row['dayid']; echo "<table cellspacing='0' border='0' cellpadding='5'> <tr> <th scope='col' width='100'></th>"; while($row_time = mysql_fetch_assoc($get_times)) { while($bool <= $days) { $row_days = mysql_fetch_assoc($get_days); $dayname = $row_days['days']; echo " <th scope='col' width='100'>$dayname</th> "; $bool++; } $day_id = 1; $timeid = $row_time['timeid']; $time = $row_time['time']; echo " <tr> <th scope='row' width='100' height='50'>$time</th>"; while($day_id <= $days) { $get = mysql_query(" SELECT * FROM $table WHERE dayid='$day_id' AND timeid_from='$timeid' AND d_m='$choose_one' ") or die(mysql_error()); if(mysql_numrows($get) > 0) { $row = mysql_fetch_assoc($get); $block = $row['block']; $apt = $row['apartment_no']; $room = $row['room_no']; $d_m = $row['d_m']; $timeid_to = $row['timeid_to']; echo " <td width='110' height='50' bgcolor='lightblue'> <b>Block:</b> $block<br /> <b>Apartment:</b> $apt<br /> <b>Room:</b> $room </td> "; //echo "</tr>"; } else { echo " <td width='110' height='50' bgcolor='green'></td> "; } $day_id++; } //end of second inner while loop echo "</tr>"; } //end of outer while loop echo "</table>"; } if($building) { if($block) { if($d_m) { if($choose_one) { if($building == 'mik') { if($block == 'Block A' || $block == 'Block B') { get_data('reserve_mik_ab', $choose_one); } else if ($block == 'Block C' || $block == 'Block D') { get_data('reserve_mik_cd', $choose_one); } } if($building == 'p') { get_data('reserve_p',$choose_one); } } else { echo "Choose one!"; } } } } ?> Please help! |