PHP - While Is Only Showing One Record
Hi guys
I am using the code below to show distinct months using one query then for each month I am trying to show a list of fixtures for the month, the problem I have is only one month is showing.
where am i going wrong?
<?php //find distinct months $sql="SELECT DISTINCT MONTH( match_date ) AS MONTH FROM tbl_fixtures WHERE season_id =$current_season UNION SELECT DISTINCT MONTH( match_date ) AS MONTH FROM tbl_gp WHERE season_id =$current_season"; $result=mysqli_query($dbConn, $sql); if(mysqli_num_rows($result)>0){ while($row=mysqli_fetch_assoc($result)){ $month=$row['MONTH']; echo '<div class="fixtureMonth"> <h2>'.$months[$month].'</h2> </div> <div class="fixtures">'; //find fixtures for month $sql="SELECT Opposition, match_date, competition, tbl_clubs.club_name AS club, image, HomeAway, team, opposition_points, points FROM tbl_fixtures INNER JOIN tbl_clubs ON tbl_fixtures.club = tbl_clubs.club_id WHERE season_id =$current_season and MONTH(match_date)=$month UNION SELECT Opposition, match_date, \"SGP\" AS competition, \"SGP\" AS club, \"sgp.png\" AS image, \"\" as HomeAway, \"\" as team, \"\" as opposition_points, points FROM tbl_gp WHERE season_id =$current_season and MONTH(match_date)=$month ORDER BY match_date"; $result=mysqli_query($dbConn,$sql)or die(mysqli_error($dbConn)); if(mysqli_num_rows($result)==0){ echo no_fixtures_found; } else{ echo '<table class="fixturesTable">'; while($row=mysqli_fetch_assoc($result)){ echo'<tr> <td>'.date("d-M-Y",strtotime($row['match_date'])).'</td> <td><img src="'.$shopConfig['url'].'images/'.$row['image'].'"/></td> <td>'.$row['Opposition'].'</td> <td>'.$row['HomeAway'].'</td> <td><b>'.$row['team'].'</b>-'.$row['opposition_points'].'</td> <td>'.$row['team'].'</td> </tr>'; } echo '</table>'; } echo '</div>'; } } ?> Similar TutorialsHey everyone, I've just undertaken my first PHP project and I'm trying to build an HTML table that lists businesses by category. The problem I am having is that the output of the PHP shows the first record in the first row both columns and this happens with every record after that. The Code: <?php // Set the error(s) reporting level error_reporting(E_ALL); ini_set("display_errors", 1); $category = "Professional Services"; // Open a connection link to your Database Engine $link = mysql_connect('localhost', 'liecon63_bizdir', 'pass') or die("Connection Error : " . mysql_error()); // Select the database to work with mysql_select_db('liecon63_bizdir') or die("Database Selection Error : " . mysql_error()); // Define your query $sqlquery = "SELECT * FROM bizdir WHERE bizcategory = '".$category."'"; // Execute the query (returning a result set in this case $sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error()); // Validate that the query returned records if (mysql_num_rows($sqlresult) > 0) { // Start display of the records echo "Business Category : " . $category . "<BR />"; echo "<table>"; // Loop through your result set to process the results while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) // here you can simply use mysql_fetch_assoc() instead { // Process your records here... like ?><table border="0" width="100%" id="table3"> <td width="400"><tr> <td><?php echo $row['bizname']; ?> <br> <?php echo $row['bizaddress']; ?> <br> <?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?> <br> <?php echo $row['bizphone']; ?></td> <td><?php echo $row['bizname']; ?> <br> <?php echo $row['bizaddress']; ?> <br> <?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?> <br> <?php echo $row['bizphone']; ?></td> </tr> </table> <? } echo "</table>"; } else { echo "No records have been found for the category " . $category; } // Close your Db Engine Link mysql_close($link); ?> The Output: <BODY onLoad="changeBkg()" id="body" TEXT="#000000" LINK="#FF0000" ALINK="#FF0000" VLINK="#FF0000"> Business Category : Professional Services<BR /><table><table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Blumstein Accounting <br> 1476 Blue Spruce Lane <br> Wantagh, New York 11793 <br> (516) 221-6161</td> <td>Blumstein Accounting <br> 1476 Blue Spruce Lane <br> Wantagh, New York 11793 <br> (516) 221-6161</td> </tr> </table> <table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Sachem Dental Group <br> 470 Patchogue Holbrook Rd <br> Holbrook, New York 11741 <br> (631) 589-8485</td> <td>Sachem Dental Group <br> 470 Patchogue Holbrook Rd <br> Holbrook, New York 11741 <br> (631) 589-8485</td> </tr> </table> <table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Care Plus Chiropractic <br> 1150 Sunrise Highway <br> Bayshore, New York 11706 <br> (631) 665-1150</td> <td>Care Plus Chiropractic <br> 1150 Sunrise Highway <br> Bayshore, New York 11706 <br> (631) 665-1150</td> </tr> </table> </table></html> Please HELP! Am adding text with paragraphs into my database but when i view that data on another page it's just one big block of text. :S Anyone no how i can stop this? I am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> I'm trying to update records in a Db. I have a record called "classOffering" and I have associated records for that offering called "classSessions". You have 1 classOffering for 1 to 6 classSessions. The process I use has the user create the classOffering and say how many classSession there will be then I create how ever many sessions they say. I then display the classSessions so they can be edited and updated in the Db. I can't seem to update and set more than one record even though there are more. I know I need to use a while or foreach statement, but I can't seem to do it. Here's my code so far: $sessSet = "UPDATE classSessions SET startDate= '$startDate', startTime= '$startTime', time= '$time' WHERE classSessions.sessionId = $sessionId "; Thanks for any help. Is it no problem to give the SUM of integers in a column, but is it also possible to give the SUM of integers in a record (automatically)?
Hey Guys, Im slowly updating our website to php/mysql, im getting there slowly but stuck at the minute. Im try to create a form where we can edit one of the pages text and then update the text in the database if that makes sense Basically at the moment i have a form where you can see the pages text like so: <table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> <tr> <td><strong>Edit About Us English </strong></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="send_update_english.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td>Detail</td> <td>:</td> <td><textarea name="detail" cols="50" rows="4" id="detail"> [b]<?php mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("SELECT body FROM aboutenglish WHERE ID = '1'"); $row = mysql_fetch_array( $result ); echo nl2br($row['body']); ?>[/b] </textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> </tr> </table> </form> </td> </tr> </table> Ive got that php bit in the middle to pull out the text thats on that page but not sure if thats correct or not. But anyways on the 'send form' page i have: <?php // Details [b]$message="$detail";[/b] mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'"); ?> the update query works if i put text in there, but when i use '$message' the database is left blank. This is only my second week doing all this stuff, so bare with me I appreciate your answers. I currently have a list of host addresses. I need to get the mx records for them. I was looking at the documentation, and found the getmxrr(). Would that send back the mx record, or just true if it has one? Hi, I have a simple mySQL database and I would like to update using a simple html form. One of the field is "accepted" and is type "boolean". I have a texbox where I will write the record id and another button which will change the "accepted" value from 0 to 1 for that record id. The problem is that I don't know how to start.... Thanks in advance Sergio New to php so I'm having trouble with deleting a record from my php table. This is my code for my page where the records are being displayed. I have a delete statement that is not working properly. Also, I was thinking maybe I need a array to delete records? Please help! Code: [Select] <?php require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_point']); $statement->execute(); $statement->closeCursor(); if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } $query = "select*from se266"; $result = mysql_query($dsn, $query); while($row = mysql_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '"name="delete[]" />'; echo ' ' .$row['grade_type']; echo ' ' .$row['grade_name']; echo '<br />'; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="grades.php" method="post"> <input type="submit" name="remove" value="Delete" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> sir i m new in php i need some help i want to go next record by clicking subbmit button here is my code: <?php mysql_connect('localhost','root',''); mysql_select_db('exam'); $sql="select * from examination"; $result=mysql_query($sql); echo $result; echo"<table><tr>"; $i = 1; while ($row = mysql_fetch_assoc($result)) { if(isset($_POST['bttn'])) { // here i want to go next record echo "<td>"; echo $row['qid']; echo "</td>"; print "</tr>"; $i++; } } Please help me I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. Code: [Select] <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> Hi all. Im trying to get a result on one of my pages where it says if a members is banned 1 or not 0, I cannt seem to get it to work. What i need is some code that says. get banned FROM usersgnet WHERE name = POST'name' Then print the banned i,.e 1 = YES 0 = NO Its just so i can tell if i have banned them or not. Thanks gnetuk Hi Guys, I appreciate your help! What I am doing is making a Choose Your Own Adventure Game and what I would like to do is the following. Record the moves of the person Put those moves on a page telling them their - say - 5 latest games Record the time it took them to complete the adventure Record that in a High Score database I know that I will need to employ the use of MYSQL databases and PHP, but I'm a total noob! Any help would be greatly appreciated! ~ Jack My form has 40 fields, and I want to re-generate it to be reviewed as it was when submitted. Next, I want to be able to UPDATE the forms values, where necessary. Is there an easy way to UPDATE the entire form from the reviewable version. Is it smarter to update ONLY the specific items that need modification? Any examples would be helpful. Hi guys, Doing a small project and i'm pretty new to php/mysql so hoping someone can help. Also i wasn't sure if this should be in php section or mysql, so apologises if it's in the wrong section. Basically... I have a form with a table in it with the fields (id, model, current stock level, new stock level) The table is populated using a mysql query to get the data from 1 table in a database. In the new stock column there's a simple text box to put a number in. Sooo like (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [ ] 3 CCC 4 [ ] A user will then put a new number in the 'new stock level' text box and when it gets submitted the new number replaces the number in 'current stock level' Basically i know how to do it if it was just the one record, but how do i get it to update all the ones with numbers in the new stock level column at the same time, and ignore it if it doesn't have anything entered in the text box? appreciate any help! thanks! Hey, I'm trying to check if a username is unique, but for some reason none of the methods that I've looked up seem to work. I'm aiming for the code to check if a username is unique, and if get the user to input the name again. $get = "SELECT `i` FROM `m` WHERE `i`=\"$r\""; $checkResults = mysql_query($getRandomness); while(mysql_num_row($checkResults) > 0) { //some code... //check again $get = "SELECT `i` FROM `m` WHERE `i`=$r"; $checkResults = mysql_query($get); } The error comes from the while line, but it comes up during the first check because the record is empty. This is the error: "Fatal error: Call to undefined function mysql_num_row()" I have a "system" setup for posting some feedback questions on an internal website. I have it setup to read a field "enabled" which has a 1 or 0. 0=disabled, 1=enabled The script works if I manually change that field, ie it reads the correct question. But need a way to have the questions listed then the one that needs to be shown on the site selected to be enabled on an admin page. Something like a list with checkboxes or radio buttons? How can I have one enabled and make sure the rest are not to prevent multiple questions being enabled? I am able to view record numbers 22, 84, and 203 by exectuing my PHP script with the correct record ID. However, what I really want to do is have a simple form whereby I can input the desired record number and have it upload the data for me. I imagine it would look something like this: "SELECT * FROM mytable WHERE id = specified_record" but need a bit of guidance to get the HTML input fields 'name' into the PHP request. Code: [Select] $sql = "SELECT poster_id from phpbb_posts WHERE topic_id = ".$topic_id." "; $result = $db->sql_query($sql); //same as mysql_query $row = $db->sql_fetchrow($result); // same as mysql_fetch array. var_dump($row); With this code (i commented the query function for you) im getting Code: [Select] array 'poster_id' => string '59' (length=2) When I run this into SQL in phpmyadmin I'm getting Code: [Select] 59 56 //this is what I want I need to get all of the records, not just the first one. I have even tried using replacing the function with mysql_query and mysql_fetch_array any ideas? It's a bit late, so I may just be making a simple mistake. Thanks! I am creating a sticky topic feature for my forum and dont know how to keep all topics marked sticky at the top of the list generated by the while loop. Any one have any ideas? They are ordered by the post date column. Here is the query: $posts_info_query = $db->query("SELECT p.post_id, p.topic_id, p.forum_id, p.post_poster, p.post_subject, p.post_content, p.post_time, p.post_edit_by, p.post_edit_date, p.post_edit_num, p.post_approved, p.post_quoting, m.user_id, m.user_username, m.user_group, m.user_regdate, m.user_birthday, m.user_online, m.user_sex, m.user_location, m.user_show_sex, m.user_show_location, m.user_show_status, m.user_avatar, m.user_sig, m.user_posts FROM ".DB_PREFIX."posts as p LEFT JOIN ".DB_PREFIX."members as m ON p.post_poster = m.user_username WHERE p.topic_id = '$topic_id' ORDER BY p.post_time ASC LIMIT $start, $limit") or trigger_error("SQL", E_USER_ERROR); Thanks |