PHP - Displaying Links Depending On Id From Another Table
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" . . . Similar TutorialsI have a video feed from two different sources. One being You Tube. I am having trouble integrating both into my code. Each works fine alone. Here is my code. Would like to display image based on feed source. either <?php print_video_thumb($post) ?> or <?php tern_wp_youtube_image(); ?> <div class="paneleft"><?php print_video_thumb($post) ?><?php tern_wp_youtube_image(); ?></div> Thanks For The Help! As I title says; I need to have an image showed the number of times, the value of a table/field.. How can I do this? hello, all: I'm a newbie, and been trying to work out a way so that the results from an array (or mysql recordset for that matter), are nicely aranged in a table. I want them to show in a grid-like manner, with rows and columns added according to number of "items". I worked out this small code snippet, with a sample array, and for the life of me, cant figure out how to make it so it automatically "breaks" columns at 5 and start new row. I got it to show me right number of rows, but then it repeats all 10 names within them, as opposed to just showing 5 names in each row... Appreciate the help... Code: [Select] <?php $names = array('Charles','Henry','Manny','Philip','Rose','Evelyn','Peter','Julia','Cary','Sophia'); $numberColumns = 5; $numberNames = count($names); $numberRows = ceil($numberNames / $numberColumns); echo "<table border='1' width='400' cellspacing='0' cellpadding='0'>"; for ($i=1; $i<=$numberRows; $i++) { echo "<tr>"; foreach ($names as $name) { echo "<td>" . $name . "</td>"; } echo "</tr>"; } echo "</table>"; ?> Hello all Ok here is the problem... I want when a user inputs the requested data to the text fields , the script to insert those data in the prope table depending on the choise the user does by choosing one option from the drop down menu. Below is the php code (apparently not working) $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $site_type = $_REQUEST['category_selection']; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Web_Sites")) { $insertSQL = sprintf("INSERT INTO partner_sites (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Blogs")) { $insertSQL = sprintf("INSERT INTO partner_blogs (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Directories")) { $insertSQL = sprintf("INSERT INTO partner_directories (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } And the html form <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="link_submission" id="link_submission"> <table width="630" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="76">URL:*</td> <td width="519"><label for="url_field"></label> <span id="sprytextfield1"> <label for="url_field"></label> <input name="url_field" type="text" id="url_field" size="50" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td> </tr> <tr> <td>Anchor Text:*</td> <td><label for="anchor_field"><span id="sprytextfield2"> <input type="text" name="anchor_field" id="anchor_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>URL Title:*</td> <td><label for="title_field"><span id="sprytextfield3"> <input type="text" name="title_field" id="title_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Description:*</td> <td><span id="sprytextarea1"> <label for="description_field"></label> <textarea name="description_field" id="description_field" cols="45" rows="3"></textarea> <span id="countsprytextarea1"> </span><span class="textareaRequiredMsg">A value is required.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></td> </tr> <tr> <td>Webmaster Name:*</td> <td><label for="textfield2"><span id="sprytextfield4"> <input type="text" name="webmaster_nane_field" id="webmaster_nane_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Webmaster E-mail:*</td> <td><label for="textfield3"><span id="sprytextfield5"> <input name="webmaster_email_field" type="text" id="webmaster_email_field" size="40" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></label></td> </tr> <tr> <td>Category:*</td> <td><span id="spryselect1"> <label for="category_selection"></label> <select name="category_selection" id="category_selection"> <option>Select An Option</option> <option value="Web_Sites">Web Sites</option> <option value="Blogs">Blogs</option> <option value="Directories">Directories</option> </select> <span class="selectRequiredMsg">Please select an item.</span></span></td> </tr> <tr> <td> </td> <td><label for="select"></label> <input type="submit" name="button" id="button" value="Url Submission" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="link_submission" /> </form> Im begging for your help..... Hi, fairly new to PHP over the last couple weeks. Been having a problem with certain queries. I have a database with football results, games, teams etc. I can filter these using drop down and that's all well and good. The problem I'm having is displaying the data via gameweek. I've been asked to display the table like so - Gameweek1 will display week1 teams, results etc. Gameweek2 will display week2... and so on.
I can manage to do this in a drop down. But I've been asked to display this using links like "Previous, 1, 2, 3 Next". I've tried pagination but I couldn't figure it out. Can anyone point me in the right direction? If I need a GET() method, how would I go about coding that so it will be used in a link(s)? Been searching and searching to find an answer but to no avail...
//Database connection etc... $gameweek = "SELECT * FROM games WHERE gameweek= 1"; //if(isset($_GET['gameweek'])) //{ // $gameweek = $_GET['gameweek']; // //} //.... $result=mysqli_query($connection, "select * from games WHERE gameweek= 1"); //Print table and table headings... mysqli_close($connection); ?> <a href="http://weeks.php?gameweek=2">Week 2</a> <a href="http://weeks.phpgameweek=3">Week 3</a> </body> </html> Hi there,
I'm a bit of a noobie, and I have a class which will allow me to send an email in html.
However when I send an email with a link such as <a href="http://www.google.com">link</a> using the html() function
The email is sent and everything is displayed corrected.
However the link isn't clickable.
Here is the code for the class.
<? class eMail { var $to = array(); var $cc = array(); var $bcc = array(); var $attachment = array(); var $boundary = ""; var $header = ""; var $subject = ""; var $body = ""; function eMail($name,$mail) { $this->boundary = md5(uniqid(time())); $this->header .= "From: $name <$mail>\n"; } function to($mail) { $this->to[] = $mail; } function cc($mail) { $this->cc[] = $mail; } function bcc($mail) { $this->bcc[] = $mail; } function attachment($file) { $this->attachment[] = $file; } function subject($subject) { $this->subject = $subject; } function text($text) { $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: 8bit\n\n"; $this->body .= $text."\n"; } function html($html) { $this->body = "Content-Type: text/html; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: quoted-printable\n\n"; $this->body .= "<html><body>\n".$html."\n</body></html>\n"; } function send() { // CC $max = count($this->cc); if($max>0) { $this->header .= "Cc: ".$this->cc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->cc[$i]; } $this->header .= "\n"; } // BCC $max = count($this->bcc); if($max>0) { $this->header .= "Bcc: ".$this->bcc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->bcc[$i]; } $this->header .= "\n"; } $this->header .= "MIME-Version: 1.0\n"; $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n"; $this->header .= "This is a multi-part message in MIME format\n"; $this->header .= "--$this->boundary\n"; $this->header .= $this->body; // Attachment $max = count($this->attachment); if($max>0) { for($i=0;$i<$max;$i++) { $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i])); $this->header .= "--".$this->boundary."\n"; $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n"; $this->header .= "Content-Transfer-Encoding: base64\n"; $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n"; $this->header .= chunk_split(base64_encode($file))."\n"; $file = ""; } } $this->header .= "--".$this->boundary."--\n\n"; foreach($this->to as $mail) { mail($mail,$this->subject,"",$this->header); } } } ?> Hello, I have a quick question about methods for retrieving records from a mysql table and displaying them as a links For example, imagine I have three tables called countries, cities and city_info. I'd like to be able to select a country and have a list of that country's city names returned as links. I'd then like to be able to click on the link for London, say, and that would trigger a mysql query to retrieve the entry in city_info about London. Are there any functions that allow this? If anyone could point me in the right direction for further research I'd be grateful. Thanks. Hi, I would like to display my master details page links to the details pages in three columns rather than a single column. Below is the do-while code I have thus far, and I am stuck. Could someone please mock up this code quick, because I know it is a simple syntax error somewhere. <?php do { echo "<table border='0'>"; for ($y=1; ; $y++) { echo "<tr>"; for ($x=1; $x<=3; $x++) { echo "<td align='left'><a href="plantdetails.php?recordID=echo $row_rsBotanicalA['PlantID'];">; echo $row_rsBotanicalA['BotanicalName']; </a></td>" } echo "</tr>"; } } while ($row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA)); echo "</table>"; ?> 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); ?> 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?? :-( 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. 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/ 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? 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); ... ?> i'm back again and i am not very good with tables as the <tr> and <td> tags confuse me i need to put 2 sets of links into 2 columns in the table and they come out jumbled up. Code: [Select] <table> <tr> <th>column 1</th> <th>column 2</th> </tr> <?php $sites = array_map('trim',file('websites.txt')); //read the whole file into an array & trim the newline character from the end of each line foreach ($sites as $link) { echo "<tr><td><a href='$link'>$link</a></td>"; } $sites = array_map('trim',file('websites2.txt')); //read the whole file into an array & trim the newline character from the end of each line foreach ($sites as $link) { echo "<td><a href='$link'>$link</a></td></tr>"; } ?> </table> I have a table and one column has links that point to index.php?id= but I want it to display the info of that row of my database. On the index.php page i have this code Code: [Select] <?php include "dbaptsConfig.php"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "id: ".$result['id']."<br />"; echo "username: ".$result['username']."<br />"; echo "type: ".$result['type']."<br />"; echo "title: ".$result['title']."<br />"; echo "description: ".$result['description']."<br />"; echo "county: ".$result['county']."<br />"; echo "town: ".$result['town']."<br />"; echo "phone: ".$result['phone']."<br />"; echo "rooms: ".$result['rooms']."<br />"; echo "bath: ".$result['bath']."<br />"; echo "squa ".$result['square']."<br />"; echo "rent: ".$result['rent']."<br />"; echo "time: ".$result['time']."<br />"; ?>I know there is something wrong with this cause I always get the same info no matter which apartment I click. Do I use the $_GET function and how do I implement this? 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.? 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! |