PHP - Displaying Group By Data
hello,
i have a table in a database that stores information on powerpoint presentations like so: id, title, filename, presenter, program, session I want to query the data so that all entries are grouped by session (which is a date) and each presentation is displayed under its respective session in a table like so: [session] (i want to display each session once) [title] - [program] (then i want to display this information for each presentation in each session) [presenter] [session] [title] - [program] [presenter] etc... i am thinking of using group_concat for this but am not sure exactly how to pull it off. any help is greatly appreciated. thank you! Similar TutorialsHi guys, Sorry - I know this is a basic question but I've been out of the game for a year now and need to jog my memory. I am trying to count the number of rows per group. e.g: $sql = "SELECT *, COUNT(id) FROM image GROUP BY city"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo $row['COUNT(id)']; So if there are, for example, 5 New York's in the table, 3 London's and 2 Sydney's I want the echo to display 5, 3, 2 Should I use a loop for this? Cheers I'm trying to output this: Status Player Player Player Status Player Player Player Status Player Player I tried this, but it didn't work: Code: [Select] while($players = mysql_fetch_assoc($results)) { foreach ($players as $player=>$status){ echo '<div>' . $player['status'] . '</div>'; foreach ($status as $key) { echo $key['playerFirst'] . ' ' . $key['playerLast'] . ', '. $key['year'] . '<br>'; } } } I guess I'm trying to find a more efficient way of doing this rather than if/elseif for each one. Right now, there are only four groupings, but in the future there could be as many 406. This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=347695.0 Hello im working on a project which involves marking attendance via an RFID tag and saving the time into an sql file. Everything seems to be working fine and the time stamp is successfully punched into the SQL but something is wrong with the php code thats supposed to display this data. Please if any one can take a look and help.
MY CODE for displaying the data (ViewAttendance.php): <?php include_once("header.php"); $attData = array(); $totDays = 0; if(isset($_REQUEST['submit'])){ $totDays = cal_days_in_month(CAL_GREGORIAN,$_REQUEST['month'],$_REQUEST['year']); $attData = $commonObj->getAttendanceData($_REQUEST['month'],$_REQUEST['year']); //print_r($attData); //print_r(date("d",strtotime($attData[0]['punch_time']))); } ?> <div class="container"> <div class="row"> <div class="col-sm-12"> <h4>Showing Attendance</h4> <form name="showAtt" method="post"> <div class="col-sm-4"><label>Select Month</label> <select name="month" class="form-control"> <?php for($i=1;$i<=12;$i++){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"><label>Select Year</label> <select name="year" class="form-control"> <?php for($i=date("Y");$i>=2010;$i--){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"> <p> </p> <input type="submit" value="Show" name="submit" class="btn btn-primary"> </div> </form> </div> </div> <div class="row"> <div class="col-sm-2"> <label class="btn btn-success btn-sm">Month:<?php echo @$_REQUEST['month'];?></label> </div> <div class="col-sm-2"><label class="btn btn-info btn-sm">Year: <?php echo @$_REQUEST['year'];?></label></div> </div> <div class="row"> <div class="col-sm-12" style="overflow: scroll;"> <?php if($totDays>0){?> <table class="table table-striped"> <tr> <th> Employee Name </th> <?php for($i=1;$i<=$totDays;$i++){?> <th> <?php echo $i;?> </th> <?php }?> <?php foreach($attData as $attk=>$attv){ $punchin = $commonObj->getTimeOfDate($attData[$attk]['punchin']); $punchout = $commonObj->getTimeOfDate($attData[$attk]['punchout']); ?> <tr> <th class="danger"> <?php echo $attv['name'];?> </th> <?php for($i=1;$i<=$totDays;$i++){?> <?php if($commonObj->getDayOfDate($attData[$attk]['punch_time']) == $i){ echo "<td class='success' id='att_$i'>".$punchin.'-'.$punchout;?> <table class="table table-responsive"style="display: none; position:relative;min-width:100px;max-width:200px; margin-top: -40px;" id="<?php echo "det_att_".$i;?>"> <tr> <td>Total hours:</td> <td><?php echo $commonObj->getHoursBetweenDates($attData[$attk]['punchin'],$attData[$attk]['punchout']);?> </td></tr> <tr> <td>UID:</td> <td><?php echo $attData[$attk]['rfid_uid'];?></td> </tr> </table> <?php }else {echo "<td class='info'>#na";}?> </td> <?php }?> </tr> <?php }?> </tr> </table> <?php }?> </div> </div> </div> </body> </html> <script> $(document).ready(function(){ $("td").hover( function () { var id = "#det_"+this.id; $(id).css({"display":"block"}); }, function () { var id = "#det_"+this.id; $(id).css({"display":"none"}); //console.log(id); //$(id).css("display","block"); }); }); </script> Display of (ViewAttendance.php):
MY SQL TABLE :
Hey guys have been trying to get this script to work for a while now, i am new to php and mysql so i am sure i am missing something simple. I have DB setup and need to pull data based on the key item code and get the following I want to get the fields item_code description allergy_statement useable_units region_availability order_lead_time ingredients for item_code 12-100 LITERALLY 12-100, no range, but like i said before i am really new to php and mysql. I have 1187 items that when a user clicks a link in search results it takes them to the product details page for that item code All that data is in my database just can't figure out how to get it out of the database. Is this even the right script to achieve that result. here is the code to get the data from database Code: [Select] <?php require_once('includes/mysql_connect_nfacts_ro.php'); $query = "SELECT item_code, description, allergy_statement, useable_units, region_availability, order_lead_time, ingredients " . "FROM products " . "WHERE item_code = '12-100' "; $resuts = mysql_query($query) or die(mysql_error()); ?> And need to display the data like so : Code: [Select] <td width="715" align="center" valign="top"> <h1>Product Details</h1> <h3>DISPLAY description HERE</h3> <table width="420" border="0"> <td class="ingreg"> </td> </table> <h5>Item Number</h5> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY ITEM_CODE HERE</td> </tr> </table> <h3>Ingredients:</h3> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY INGREDIENTS HERE</td> </tr> </table> <h4>Allergy Statement:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Allergy Statement HERE</td> </tr> </table> <h4>Useable Units Per Package:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Useable Units Per Package HERE</td> </tr> </table> <h4>Region Availability: </h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY ITEM_CODE HERE</td> </tr> </table> <h4>Order Lead Time:</h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY order lead time HERE</td> </tr> </table> <p> </p> <div align="right"></div></td> </tr> </table> how do i get data in database to display where i need it to? Can any one shine some light on this So I have an simple account centre up, and i'm wanting to display their 'Name' 'Username' and 'Email' as part of their details. But I have one problem... My code doesn't seem to be getting the data from my database... It may be messy to some people, just warning you! Code: [Select] <?php session_start(); if($_SESSION['username']){ $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $sql = mysql_query("SELECT * FROM login"); $username = $rows['username']; $email = $rows['email']; $rows = mysql_fetch_assoc($sql); echo "<p>"; } else header("location: suggestion.html"); ?> <!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>Untitled Document</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #CCC; } body,td,th { color: #000; font-family: "MS Serif", "New York", serif; } </style> </head> <body> <div id="wrap"> <!--Header--> <div id="header_member"> </div> <!--Log out and time--> <div id="info"> <div id="date"><script type="text/javascript"> var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.write("<b>" + day + "/" + month + "/" + year + "</b>") var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes()</script> </div> <div id="time"><script type="text/javascript"> var suffix = "AM"; if (hours >= 12) { suffix = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) minutes = "0" + minutes document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")</script> </div> </div> <div id="logout"><center><?php echo "<a href='logout.php'>Log out.</a>";?></center></div> <!--Main section which will contain everything else--> <div id="member_main"> <div id="member_right"><center> <p><img src="images/accountinf.png" width="175" height="30" /></p> <p>Name: <?php echo $username;?></p> <p>Email: <?php echo $email;?></p> </center> </div> <div id="member_top"><center><?php echo "Welcome, ".$_SESSION['username'];?></center></div> <div id="member_left" align="center"><img src="images/navigation.png" width="105" height="30" /><img src="images/home_member.png" width="105" height="30" /><img src="images/account.png" width="105" height="30" /></div> </div> <!--Footer--> <div id="footer_member"></div> </div> </body> </html> So i pull some records out of a mysql table and i want to display them in 5 even columns. I'm not entirely sure how to do the math & logic to accomplish this. The pull is simple $qry = "SELECT DIST_PART_NUM FROM $tablename"; $sql = mysql_query($qry) or die(mysql_error()); while($res = mysql_fetch_assoc($sql)) { // CREATE 5 even columns here. } so let's say i just retrieved 5,000 part numbers, i'd like to display then in a table of 5 columns with 1000 records per column. This is easy math, but i need the script to automatically figure out the #'s. Also the tricky part is that i dont want to display the part numbers like so 11111 22222 33333 44444 55555 66666 77777 88888 99999 00000 but rather 11111 44444 77777 22222 55555 88888 33333 66666 99999 00000 the remainder if there is one can go in the last column or whatever is easier. I'd tried googling this, but it's not easy to phrase what i'm looking for. Thanks for the help. PS: I'm not looking to copy and paste code, if possible please explain your way so that i can learn the logic. 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? Ok... I need some help - I want to show a players balance in a game beside there name (Balance is in mysql database)I can do that but... - I also want to show if there online or offline at the same time( This is stored in a different database) I have the code which says whether they are online or offline <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='black'>|Online|<br><font color='green'>$users</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; ?> Here is the page: www.scswc.com/Offline_Users.php displaying that But I want to Create something like this: Nocvacraft Players |Online| Name:Player Balance:$20 |Offline| Name:Player Balance:$15 Here is what I have tried: <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","**********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); $query2 =mysql_query("SELECT * FROM iBalances WHERE player = $users"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query) $rows2 = mysql_fetch_array($query2)): $users = $rows['name']; $balance = $rows2['balance']; echo "<font color='black'>|Online|<br><font color='green'>Name:$usersBalance:$balance</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; ?> I know I am trying to use a variable before it is been set - but if I don't how I have tried this as well... <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","**********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='black'>|Online|<br><font color='green'>Name:$users</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; $query = mysql_query("SELECT * FROM iBalances WHERE player = $users"); WHILE($rows = mysql_fetch_array($query)): $balance = $rows['balance']; echo "<font color='red'>$users $balance</font><br>"; endwhile; // ?> Can you use variables in mysql_query()?Is that why it isn't working? This is my first php script so if I need to give you more information for you to help me just tell me Thanks Here is database pictures iBalances users_online Hi, I'm trying to joing two tables together, in the resulting PHP coding (See below) the issue I'm having the coding saying select the colour from the colour table where the model of car is the same as the model in the cars table. For example, if the car model is KA and in the table it is KA show the colours. I know this manual fix does the trick. [ $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = '$test' "; ] But not the soultion any help would be much appericated thank you. [ include "connections/dbconnect.php"; $manfactures = "Ford"; $car_query = "SELECT * FROM cars WHERE make = '$manfactures'"; $car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error()); setlocale(LC_MONETARY, 'en_GB'); $fmt = '%i'; if (mysql_num_rows($car_result) > 0) { while ($car_row = @ mysql_fetch_array($car_result)) { $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = cars.model"; $cols_result = mysql_query($query_cols) or die ("Error in query: $query_cols. ".mysql_error()); print " <table class='details'> <tr> <td rowspan='2'> <img src=\"". $car_row["image"] ."\" alt='" . $car_row["image_alt"] . "' /> </td> <td colspan='2'> <a href='" . $car_row["what_link"] . "'> " . $car_row["model"]." ".$car_row["model_details"] . " </a> </tr> <tr> <td> <p class='info'> RRP:<br/> What Price:<br/> Our Price:<br/> Savings of:<br/> Delivery Time: </p> </td> <td> <p class='info1'> "; echo money_format($fmt, $car_row["rrp"] ); print "<br/>"; echo money_format($fmt, $car_row["what_price"] ); print "<br/>"; echo money_format($fmt, $car_row["our_price"] ); $savings = $car_row["rrp"] - $car_row["our_price"]; print " <br/> <font color=\"red\">"; echo money_format($fmt, $savings ); print " </font><br/> " . $car_row["delivery_time"] . " </p> </td> </tr> <tr> <td> "; while ($cols_row = @ mysql_fetch_array($cols_result)) { ?> <a href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $cols_row["colour"] . ""; ?>");return false'> <?php print " <img src=\"". $cols_row["colour_img"] ."\" alt='" . $cols_row["colour_img_alt"] . "' /> "; } print " </td> </tr> "; } } else { echo "Aids!"; } print "</table>"; ?>] PHP Code Code: [Select] <?php $username=""; $password=""; $database=""; mysql_connect("","",""); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"id"); $field2-name=mysql_result($result,$i,"Location"); $field3-name=mysql_result($result,$i,"Property type"); $field4-name=mysql_result($result,$i,"Number of bedrooms"); $field5-name=mysql_result($result,$i,"Purchase type"); $field6-name=mysql_result($result,$i,"Price range"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> HTML code for the form Code: [Select] <table id="tb1"> <tr> <td><p class="LOC">Location:</p></td> <td><div id="LC"> <form action="insert.php" method="post"> <select multiple="multiple" size="5" style="width: 150px;" > <option>Armley</option> <option>Chapel Allerton</option> <option>Harehills</option> <option>Headingley</option> <option>Hyde Park</option> <option>Moortown</option> <option>Roundhay</option> </select> </form> </div> </td> <td><p class="PT">Property type:</p></td> <td><div id="PS"> <form action="insert.php" method="post"> <select name="property type" style="width: 170px;"> <option value="none" selected="selected">Any</option> <option value="Houses">Houses</option> <option value="Flats / Apartments">Flats / Apartments</option> </select> </form> </div> </td><td> <div id="ptype"> <form action="insert.php" method="post"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </form> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <form action="insert.php" method="post"> <select name="number of bedrooms"> <option value="none" selected="selected">No Min</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> to <select name="number of bedrooms"> <option value="none" selected="selected">No Max</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </form> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <form action="insert.php" method="post"> <select name="price range"> <option value="none" selected="selected">No Min</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> to <select name="price range"> <option value="none" selected="selected">No Max</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> </form> </div> </td> </tr> </table> </div> <form id="submit" action=""> <input type="submit" value="search" /> </form> I have page1.php which has a post form and page2.php which display data/results. I have a seperate php script file which queries a database. Having completed the query and assuming a result, I would end up with something like Code: [Select] while($result = mysql_fetch_assoc($query)) how do I get the data onto the display page. Looking at example approaches I found this using a go-between file Code: [Select] <?PHP include_once(process.php; process($_POST); display_results; ?> would display_results be a form of redirect? If not? Any help appreciated. I am trying to display data from a database from a form entry here is the php <?php include('dbconnect.php'); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM child_info"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"file_number"); $field2-name=mysql_result($result,$i,"first_name"); $field3-name=mysql_result($result,$i,"middle_name"); $field4-name=mysql_result($result,$i,"last_name"); $field5-name=mysql_result($result,$i,"birthdate"); $field6-name=mysql_result($result,$i,"gender"); $field7-name=mysql_result($result,$i,"features"); $field8-name=mysql_result($result,$i,"diagnosis"); $field9-name=mysql_result($result,$i,"description"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> here is the form I am using <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td> Search by Name: </td> <td> First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br /> Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" /> </td> </tr> <tr> <td width="208"> Choose Male or Female: </td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td> Choose age range: </td> <td> <select name="first_age" id="first_age"> <option value="00">From</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> <select name="second_age" id="second_age"> <option value="00">To</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div></td> </tr> </table> </form> first problem is getting the form to use the php second problem is when i try to use the php alone is I get this error Parse error: syntax error, unexpected '=' in /home/fathersh/public_html/selectdata.php on line 17 17 is highlighted above in the php 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. Hi guys, I have a problem.. I have a table which shows the results, but the table is showing right at the bottom below the button "delete members" although the code is right above it so I don't really understand.. and hope someone can shed the light? Appreciated Code: [Select] <?php include "connect.php"; session_start(); if(!isset($_SESSION['email'])) { die('You have no access to this page.'); } else{ //Check if records were submitted for deletion if(isset($_POST['id']) && count($_POST['id'])) { //Ensure values are ints $deleteIDs = implode(', ', array_map('intval', $_POST['id'])); $query = "DELETE FROM member WHERE id IN ({$deleteIDs})"; //Debug line echo "Successfuly deleted member(s)"; mysql_query($query) or die(mysql_error()); } ?> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container"> <h1>Consult, Modify or Delete a Member</h1> <form id="form_362567" class="appnitro" method="post" action="searchmember.php"> <div class="form_description"> <h2> Consult, Search, Modify or Delete a Member</h2> <p></p> </div> <ul > <li class="section_break"> <br>Search members with any keyword or character within the options id/email/firstname/lastname/phone/address1/address2/city/county/postcode - relevant matches will show.<br><br> <b>Keyword/Character:</b><br> <input id="search" name="search" class="element text medium" type="text" maxlength="50" value=""/> <br><br> <b>Search on</b>:<br> <select name="searchvalue" id="searchvalue"> <option name="id" id="id">id</option> <option name="email" id="email">email</option> <option name="firstname" id="firstname">firstname</option> <option name="lastname" id="lastname">lastname</option> <option name="phone" id="phone">phone</option> <option name="address1" id="address1">address1</option> <option name="address2" id="address2">address2</option> <option name="city" id="city">city</option> <option name="county" id="county">county</option> <option name="postcode" id="postcode">postcode</option> </select><br><input type='submit' value='Search' name='go' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> <br> To consult or modify a profile click on the member's E-mail address. <li class="section_break"> </form> <?php $result = mysql_query("SELECT * FROM member"); ?> <table border='1'> <tr> <th>First Name</th> <th>Last Name</th> <th>Phone Number</th> <th>Postcode</th> <th>E-mail</th> <th>Delete</th> </tr> <?php while($row = mysql_fetch_array($result)) { echo "<form action='' method='POST'>"; echo "<tr>"; echo "<td>" . $row['firstname'] . "</td>"; echo "<td>" . $row['lastname'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "<td>" . $row['postcode'] . "</td>"; echo "<td>"; echo '<a href="consultmember.php?email='; echo $row['email']; echo '">'; echo $row['email']; echo "</a></td>"; echo "<td><input type='checkbox' name='id[]' value='{$row['id']}' /></td>"; echo "</tr>"; } ?> <br><input type='submit' value='Delete Members' name='delete' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> </form> <div id="footer"> </div> </div> <img id="bottom" src="bottom.png" alt=""> </body> <?php } ?> Hello, I'm trying to build a registration/login system. I managed to set it up but i need that for the user when he/she is logged in to display his own information and to manage to edit them, First i need to display them, because i seem to not be doing it.. i know it's easy in principal but i am really new at this... So here is my code: The login.php page Code: [Select] <?php include ('database_connection.php'); if (isset($_POST['formsubmitted'])) { // Initialize a session: session_start(); $error = array();//this aaray will store all error messages if (empty($_POST['e-mail'])) {//if the email supplied is empty $error[] = 'You forgot to enter your Email '; } else { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) { $Email = $_POST['e-mail']; } else { $error[] = 'Your EMail Address is invalid '; } } if (empty($_POST['Password'])) { $error[] = 'Please Enter Your Password '; } else { $Password = $_POST['Password']; } if (empty($error))//if the array is empty , it means no error found { $query_check_credentials = "SELECT * FROM members WHERE (Email='$Email' AND password='$Password') AND Activation IS NULL"; $result_check_credentials = mysqli_query($dbc, $query_check_credentials); if(!$result_check_credentials){//If the QUery Failed echo 'Query Failed '; } if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull { // A match was made. $_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable header("Location: page.php"); }else { $msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect'; } } else { echo '<div class="errormsgbox"> <ol>'; foreach ($error as $key => $values) { echo ' <li>'.$values.'</li>'; } echo '</ol></div>'; } if(isset($msg_error)){ echo '<div class="warning">'.$msg_error.' </div>'; } /// var_dump($error); mysqli_close($dbc); } // End of the main Submit conditional. ?><!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>Login Form</title> <style type="text/css"> body { font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; font-size:12px; } .registration_form { margin:0 auto; width:500px; padding:14px; } label { width: 10em; float: left; margin-right: 0.5em; display: block } .submit { float:right; } fieldset { background:#EBF4FB none repeat scroll 0 0; border:2px solid #B7DDF2; width: 500px; } legend { color: #fff; background: #80D3E2; border: 1px solid #781351; padding: 2px 6px } .elements { padding:10px; } p { border-bottom:1px solid #B7DDF2; color:#666666; font-size:11px; margin-bottom:20px; padding-bottom:10px; } a{ color:#0099FF; font-weight:bold; } /* Box Style */ .success, .warning, .errormsgbox, .validation { border: 1px solid; margin: 0 auto; padding:10px 5px 10px 60px; background-repeat: no-repeat; background-position: 10px center; font-weight:bold; width:450px; } .success { color: #4F8A10; background-color: #DFF2BF; background-image:url('images/success.png'); } .warning { color: #9F6000; background-color: #FEEFB3; background-image: url('images/warning.png'); } .errormsgbox { color: #D8000C; background-color: #FFBABA; background-image: url('images/error.png'); } .validation { color: #D63301; background-color: #FFCCBA; background-image: url('images/error.png'); } </style> </head> <body> <form action="login.php" method="post" class="registration_form"> <fieldset> <legend>Login Form </legend> <p>Enter Your username and Password Below </p> <div class="elements"> <label for="name">Email :</label> <input type="text" id="e-mail" name="e-mail" size="25" /> </div> <div class="elements"> <label for="Password">Password:</label> <input type="password" id="Password" name="Password" size="25" /> </div> <div class="submit"> <input type="hidden" name="formsubmitted" value="TRUE" /> <input type="submit" value="Login" /> </div> </fieldset> </form> Go Back to <a href="#">Account Verification on sign up</a> </body> </html> This is the page's code where user is redirected after login Code: [Select] <?php ob_start(); session_start(); if(!isset($_SESSION['Username'])){ header("Location: login.php"); } ?> <!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>Member Area </title> <style type="text/css"> .success { border: 1px solid; margin: 0 auto; padding:10px 5px 10px 60px; background-repeat: no-repeat; background-position: 10px center; font-weight:bold; width:450px; color: #4F8A10; background-color: #DFF2BF; background-image:url('images/success.png'); } </style> </head> <body> <div class="success">Welcome , <?php echo $_SESSION['Username'] ; ?></div> <? $b = time (); $date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); $str_time = "&receivedtimestamp="; $str_msg = "&msg=bkt"; $str_from = "from="; ?> <a href="http://testext.i-movo.com/api/receivesms.aspx?<?echo $str_from;?><?echo $_SESSION['phone'];?><?echo $str_time;?><?echo $date1;?><?echo $str_msg;?>">Get a Cupon</a> </br> <?php echo $_SESSION['Email'] ; ?> </br> <?php echo $_SESSION['phone'] ; ?> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> </body> </html> And finally the database structure is this one ... Code: [Select] CREATE TABLE IF NOT EXISTS `members` ( `Memberid` int(10) NOT NULL AUTO_INCREMENT, `Username` varchar(20) NOT NULL, `Email` varchar(50) NOT NULL, `Password` varchar(10) NOT NULL, `phone` varchar(25) NOT NULL, `Activation` varchar(60) DEFAULT NULL, PRIMARY KEY (`Memberid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ; Please help me with this because i'm going mad I am querying my database to show the visit statistics for a particular week and it shows the number of visits for the countries, but does not display the country name.
I have proved that the MySQL works by going into phpMyAdmin and pasting the query into SQL query tab, replacing the POST with 1, for week 1.
I can't see why it is not displying the country.
Here is the code:
<?php include('connect_visits.php'); doDB7(); $WVisit_data="SELECT WeekNo15.WNo, WeekNo15.WCom, Countries.Country, Countries.CID, ctryvisits15.CVisits FROM ctryvisits15 LEFT JOIN Countries ON ctryvisits15.country = Countries.CID LEFT JOIN WeekNo15 ON ctryvisits15.WNo = WeekNo15.WNo WHERE ctryvisits15.WNo = '{$_POST['WeekNo']}' ORDER BY ctryvisits15.CVisits DESC"; $WVisit_data_res = mysqli_query($mysqli, $WVisit_data) or die(mysqli_error($mysqli)); $display_block =" <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Country</th> <th>Visits</> </tr>"; while ($WV_info = mysqli_fetch_array($WVisit_data_res)){ $Ctry = $WV_info['country']; $Visits = $WV_info['CVisits']; //add to display $display_block .=" <tr> <td width=\"10%\" valign=\"top\">".$Ctry."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> "; } mysqli_free_result($WVisit_data_res); mysqli_close($mysqli); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Stats for country</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="menu"> <ul> <li class="current_page_item"><a href="index.php">Home</a></li> <li><a href="Links.html">Links</a></li> <li><a href="Verse_Menu.html">Verses</a></li> <li><a href="Techniques.html">Techniques</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="AboutUs.html">About Us</a></li> <li><a href="stats1.html">Stats</a></li> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h3>Statistics for Week Commencing <? echo $WkCom; ?> in 2015</h3> <div id="table"> <?php echo $display_block; ?></div> </div><!-- end #content --> </body> </html>Can you help please? Edited by rocky48, 07 January 2015 - 07:33 AM. Hi guys. I'm trying to build a games site for a friend. Currently, the front-end (HTML/CSS) of the site is done. Now, I want to make a way for him to easily add games to the site. Ideally, I'd like to make a database with the following columns: ID, Name, Category, Link, Thumbnail_Link. So, those would be the ID, name of the game, the category, a link to the game, and a link to the 50x50 thumbnail image respectively. Then, using PHP, I'd like to call the first x number (not sure what it will be yet, let's say 50) and make format it as a grid in the following way: There's the thumbnail image followed by the game name, and they're all a clickable link to the game URL. Is this possible? How would I go about doing this? I've already set up a database for a login module to the site, so each page has already opened a connection to the MySQL database. However, I've only ever done basic PHP for mail forms and am otherwise extremely new to it, and am especially new to MySQL. Could anyone walk me through how to do this or even give me a quick example script to work off of? Thanks, any of your time is greatly appreciated! |