PHP - Get/display Data
Hi all. The following is a function to get and display data. However, I've hit a wall in my progress. It's only printing out one field. I need to have it print out every retrieved field. Any help is appreciated.
function get_data($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=0; while($i < $num){ $fields=mysql_fetch_field($result,$i); $display_fields=mysql_result($result,$i,$fields->name); echo $display_fields; $i++; }; }; I realized that (I think) I need the $display_fields var to be concatenated with the $i variable so there's a unique var name for each field retrieved from the mysql_fetch_field line. Any ideas? Similar TutorialsHello, I just reach the ultimate high in frustration because i can not display all the data from my database in a table using php. Im trying to display all the members from my database (id, username, email and account type) in my admin cp, and what is happening is that i am displaying all my data in one td. (Ex, in the <td></td>, it will display all the usernames at once, rather than separating them). Code: [Select] <?php include_once "../config.php"; include_once "admin_check.php"; $get_members = mysql_query("SELECT * FROM members ORDER BY id"); while ($row = mysql_fetch_array($get_members)) { $id .= $row['id']; $username .= $row['username']; $account_type .= $row['account_type']; $email .= $row['email']; } ?> <!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>Welcome Admin!</title> </head> <body> <h1>Welcome admin! <a href='../index.php'> Click here to go back! </a></h1> <table cellspacing="5" cellpadding="5" style="border: black thin solid" align="center"> <tr> <td>ID</td> <td>Username</td> <td>Email</td> <td>Account Type</td> </tr> <tr> <td><?php echo $id;?></td> <td><?php echo $username;?></td> <td><?php echo $email;?></td> <td><?php echo $account_type;?></td> </tr> </table> </body> </html> Now i tried making the table in the while loop, but i am also having the same problem. Please help. Hello. What I have created is a menu with links. The links will display content on the page from a database. I have the links with id displayed, but nothing is displayed when the link is clicks. I have seen isset() and $_GET used but not a form and I don't know how to change the code to allow the display of data using ID. My site is local, and I am using XAMPP. The database connections work. This is my code: // query $query = "SELECT * FROM topmenu ORDER BY id ASC"; $row = $PDO->query($query); .... <table class="topmenu"> <tr> <td> <h1 class="siteName">site title</h1> </td> <?php foreach($row as $data) { ?> <td><a href="index.php?id=<?php echo $data['id']; ?>"> <?php echo $data['menuheader']; ?> </a></td> <?php } ?> </tr> </table> As a beginner, I would appreciate any help, no criticism of my code please! Also, is there a way of hiding the id in the url? Thanks in advance. How do you display non-editable data that is part of a larger form? For instance, I have an "Add a Comment" for with... =========================== * Article Title (non-editable) * Name (non-editable) * Comment (editable) Submit button =========================== Do I just make a Form with one Input field for the editable field?! And then make the first two "fields" stylized <p> tags?? Debbie I am developing a script for hospital. I have wards like General, Delux, ICU etc. Each ward can have number of patients. Each nurse will be allocated to some wards in weekly basis. Now I want to display for the nurse that how many patients are there in the ward which is allocated to her/him on that week. Here is my wards table
Here is my ward allotment for each nurse
And patient admitted details i get from admission table, which is like this
Now i want to show result like this
From 16/09/2019 to 22/09/2019 General Ward Patient bed No shift HSSC022 3 1 ICU HSSC014 1 1 I have written query like this, but it doesn't show this way $firstday = date('Y-m-d', strtotime("this week monday")); $lastday = date("Y-m-d", strtotime("this week sunday")); "SELECT wa.sdate, DAYNAME(wa.sdate) AS Day, wa.shift, w.ward_name, a.patient_id, a.ward, p.patient_name FROM ward_allotment wa INNER JOIN admission a ON wa.ward=a.ward INNER JOIN patient p ON a.patient_id=p.patient_id INNER JOIN wards w ON wa.ward=w.wid WHERE wa.week=".$_SESSION['Cweek']." AND a.from_date>='".$firstday."' AND a.discharge_date='0000-00-00' AND wa.nurse=".$_SESSION['user_id']." GROUP BY a.patient_id"; Can somebody help me how to do it.
This is the php code i have wrote but i need some help....as this code is displaying my value from database when time(which is saved in database too) is equal to current server time. let say e.g : time saved in database is 6:00:00, so when current time is equal to database time which is 6:00:00 it then display my stored value(e.g 40 (int) ) from database. which is : 40 so i need help out here when the value shows : 40 on exact 6:00:00 (time) but disappear after a second i want to be display this value for 30 more sec.after that a new value from database will come and diplay as the time goes to 6:00:30 hope friend you will help me out soon thank you below is the code of php file. // First Connect to database echo "<meta http-equiv='refresh' content='20'>"; $link = mysql_connect("$dbhost","$dbuser","$dbpass") or die(mysql_error()); // Connection starts here mysql_select_db("$dbname") or die(mysql_error()); $sql = "SELECT * FROM datatable WHERE time = '$ctime' "; // simple sql example echo $cdate; echo "<br>"; echo $ctime; $re = mysql_query($sql) or die(mysql_error()); // Here's where you'll get an error if the SQL is invalid. while($row = mysql_fetch_array($re)) { // Beganing 1 include("variables.php"); echo "<br>"; echo $row['value']; // value to be displayed for 30Sec after displayed on site. } //Closing 4 mysql_close($link); // code ends here..:-) Hi all, I am a php student and i am doing a project in php. I am doing the project of online attendance register. I am stuck with the part of reports. We need to select three different values from an HTML form and pick the selected rows and wants to display those rows in a table. I have done a code but it is not working. Please help me out of this issue. HTML Form: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body><form action="reportpro.php" method="get" name="services"> <table width="447" border="0" align="center" > <tr style="text-align: center"> <td width="441"><table width="481" border="1"> <tr> <td width="216"><div align="center"> SECTION </div></td> <td width="102"><div align="center"> MONTH </div></td> <td width="141"><div align="center"> YEAR </div></td> </tr> <tr> <td><select name="section" id="select"> <option>SERVICES-A</option> <option>SERVICES-B</option> <option>SERVICES-C</option> </select></td> <td><select name="month" id="select"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select></td> <td><select name="year" id="select"> <option>2014</option> <option>2015</option> <option>2016</option> <option>2017</option> <option>2018</option> <option>2019</option> <option>2020</option> </select></td> </tr> <tr> <td colspan="4"> <center><input name="submit" type="submit" id="submit" formaction="reportpro.php" formmethod="get" value="Search"></center></td> </tr> </table> <p> </p> <p> </p> <p> </p></td> </tr> </table> </form> </body> </html> PHP Code: <!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> </head> <body> <form action="" method="get"> <table border="1" align="center" > <tr> <td>BOOK NO</td> <td>Name</td> <td>Desigination</td> <td>Section</td> <td>Day</td> <td>Month</td> <td>Year</td> <td>Attendance</td> </tr> <?php $con=mysql_connect("localhost","root",""); mysql_select_db("niy",$con); $m=$_REQUEST['month']; $y=$_REQUEST['year']; $sec=$_REQUEST['section']; $sql="select month='$m', year='$y', sectn='$sec' from attendance "; echo $sql; $res=mysql_query($sql,$con); while($row=mysql_fetch_array($res)) { ?> <tr> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><?php echo $row[5];?></td> <td><?php echo $m;?></td> <td><?php echo $y;?></td> <td><?php echo $row[8];?></td> </tr> <?php } ?> </table> </body> </html> I want to fetch data from a table let's say table "activities". Uid | day | activity | time | remarks 1. Mon. Act1. 3pm. Good 2. Mon. Act1. 5pm. Bad 1. Tue. Act2. 12am. Bad 1. Tue. Act5. 1am. Bad 1. Thur. Act8. 9pm. Good 2. Wed. Act4. 7am. Good
Now assuming I want to fetch all the data that is related to user Id 1 and display them in another table (Uid 1). Which is 4 rows according to the table, how do I go about it using select query? Thanks!!! I tried something like this but it displays just one row <?php $uid = $_SESSION['login']; $sql2 = "SELECT * FROM Activities WHERE uid=? ORDER BY Uid LIMIT 6"; $stmt2 = $connection->prepare($sql2); $stmt2->bind_param('i', $Uid); $stmt2->execute(); $result2 = $stmt2->get_result(); $row2 = $result2->fetch_assoc(); //now am stuck here ?> now trying to display the fetch those data for only Uid 1 in these simple format...
<table style="width:100%"> <tr> <th>Day</th> <th>Activity</th> <th>Remarks</th> </tr> <tr> <td>Mon</td> <td>Act1</td> <td>Good</td> </tr> <tr> <td>Tue</td> <td>Act2</td> <td>Bad</td> </tr> <tr> <td>Tue</td> <td>Act5</td> <td>Bad</td> </tr> </table>
The program is working for part of the data . It can display in the CSS and HTML code, however, the other data can not display . I do not why . They are same structure . Please tell me the reason. Thank you very much. It's very possible, and I've seen a website that's done it (http://www.zybez.net/radio/) - They are able to include the recent songs played on there website. The information can be obtained from right he http://68.168.100.60:7942/played.html But I'm not sure if thats where they get it from. If I login to my Admin section, there will be an option that says get XML stats. But I'm not sure if that shows the recent songs played like it would at http://68.168.100.60:7942/played.html (Everytime I refresh the page, the stats/data/info in the XML change) Code: [Select] 1250001522Rockhttp://srbuckey.listen2myradio.comMusicPEAK - RockKings of Leon - Radioactive N/AN/AN/A226153140audio/mpeg1.9.86201901701119000000004013207.144.125.60NSPlayer/11.0.6001.7006 WMFSDK/11.0026101521287587284Kings of Leon - Radioactive 1287586919Three Days Grace - Riot 1287586542Alice In Chains - Here Comes The Rooster 1287586281Green Day - Boulevard of Broken Dreams 1287586277down 1287586075Green Day - American Idiot 1287586044Metallica - Enter Sandman 1287585836ACDC Highway To Hell.mp3 1287585449Metallica - 04 The Unforgiven I.MP3 1287585448[HTTP/1.1 200 OK] http://www.ventsi.com/Music/MetallicA/1991 - Black Album/Metallica - 04 The Unforgiven I.MP3 I'm not sure what I'm doing wrong here... This is my index <html <head> <title>Admin applications</title> </head> <body text="#000000"> <center> <?php include("connect.php"); echo "<table cellpadding='3' cellspacing='2' summary='' border='3'>"; echo "<tr><td>Real name:<br><br>"; echo $row['real_name']; echo "</td><td>Age:<br><br>"; echo $row['age']; echo "</td><td>In-Game Name:<br><br>"; echo $row['game_name']; echo "</td><td>Steam ID:<br><br>"; echo $row['steamid']; echo "</td><td>Agreement:<br><br>"; echo $row['agreement']; echo "</td><td>Will use vent:<br><br>"; echo $row['vent']; echo "</td><td>Activity:<br><br>"; echo $row['activity']; echo "</td><td>Why this person wants to be an admin:<br><br>"; echo $row['why']; echo "</td></tr></table>"; ?> </center> </body> </html> and this is my database connect <?php $database="admin"; mysql_connect ("localhost", "root", "waygan914"); @mysql_select_db($database) or die( "Unable to select database"); mysql_query("SELECT * FROM applications"); ?> The database table "applications" has 8 fields, and 2 records, but when I view the page i get the table but no data: hey der.... m a newbie to php and i dont know if this is the right place for this post. i have a php code and i would like it to be displayed on the browser as well as store it in mysql server in i proper format.... i tried to work with cookies but got the data displayed in array format please help me store it and display it separately i.e., name="XXXX" age="YY".........and so on the code i used in cookies is as follows <?php setcookie("name", $_POST["name"], time()+3600, "/","", 0); setcookie("age", $_POST["age"], time()+3600, "/", "", 0); ?> when i retrieve the cookie data by <?php print_r($_COOKIE)?> i get the output as: Array ( [name] => mohit [age] => 22 ) last but not the least to put the value of the cookie in mysql any help appreciated.... thnx I have a page which displays an item based on a search. Below is the code. Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<div id='item'>"; // div class 'item' echo "<div class='item_left'>"; echo "<p>"; echo $row['prod_descr']; echo "</p>"; echo "<p>"; echo "£" . $row['price']; echo "</p>"; echo "</div>"; echo "<div class='item_right'>"; echo "<img src='db/images/".$row['image']."' />"; $showHeader = false; echo "<br />"; echo "You may also like...."; echo $row['product']; echo "</div>"; } } ?> <p> <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="item_name" value="<?php echo $row['product']; ?>"> <input type="hidden" name="item_number" value="<?php echo $row['prodID']; ?>"> <input type="hidden" name="amount" value="<?php echo $row['price'] ?>" /> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </p> <?php echo "</div>"; // End of div class 'item' echo "</div>"; } include ('./includes/footer.html'); ?> What I want to achieve is just below the product content, is a feature with one or two random records which will essentially say to the user "you may also like" and display random but similar products. How do I achieve this? I am managing a shop website which is using php and mysql for data. The website has a section that will display the related products with the one that you are watching. Now my problem is that if there are more than 5 items it will continue to display all the items in one row with the consequent that the page will not display well. I need to find a way to begin a new row after the 5th item so it will display 5 items in each row. this is my current code that is responsible for showing the related items. There is also a picture attached with the problem. while ($row = mysql_fetch_array($retd)) { $code = $row["code"]; $name = $row["name"]; echo("<td width=150 align=center>"); echo ("<a href=../products/info.php?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>"); echo ("<br><a href=../products/info.php?scode=$code><span class=fs13>$name</span></a>"); echo("</td>"); } Does anyone know how can I do this? Hello everyone, I'm trying to create a page that takes information from an existing database and displays it in a 'table' on a page. The table thing didn't seem to be working with some other pages I was working on so I split each database table into its own html table and rearrange accordingly. The code below doesn't output any information and I can't figure out why. Thanks in advance. $query = mysql_query("SELECT MAX(ART_ID) AS maxAID FROM Artisan"); while(mysql_fetch_array($query)) { $maxAID = $row["maxAID"]; for($artID = 1; $artID <= $maxAID; $artID++) { $Aquery = mysql_query("SELECT * FROM Artisan WHERE ART_ID = '$artID'"); ?> <table align = "center" width="90%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $ART_Name = $row["ART_Name"]; ?> <tr> <td><?php echo $ART_Name; ?></td> <td> Filler </td> </tr> <?php }?></table><?php $Qquery = mysql_query("SELECT * FROM ArtisanQuestion ORDER BY ARQ_ID"); ?> <table align = "left" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Qquery)) { $Ques_ID = $row["ARQ_ID"]; $Ques = $row["ARQ_Question"]; ?> <tr> <td><?php echo "<b>".$Ques_ID."</b>. ".$Ques; ?></td> </tr> <?php }?></table><?php $Aquery = mysql_query("SELECT * ArtisanAnswer WHERE ART_ID = '$artID' ORDER BY ARQ_ID"); ?><table align = "right" width="35%" border="0" style="font-size: 12px; margin-top: 30px; font-family: Tahoma;"> <?php while(mysql_fetch_array($Aquery)) { $Ans = $row["ARAN_Answer"]; ?> <tr> <td><?php echo $Ans; ?></td> </tr> <?php }?></table><?php } } ?> I have a page in my admin control panel which allows for adding and editing an existing entry on the same page. At the moment, it displays the entries on the page in a table like format. After I edit an entry and hit Submit, I display a message on that page that says "Link updated successfully!", but the table on the page doesn't load the new entry until I refresh again - obviously since the data isn't entered into the database until I hit the submit button to process the form. But I'm wondering if it's possible to update the table on the page and display that new updated table all after hitting the submit button?? Hi, i need help for get data from following tables:
questions:
id
question
options:
id
ques_id
value
votes:
id
option_id
voted_on
ip
Question: What is your favorite color.
Option1: Test 1 - 83 votes
Option2: Test 2 - 0 votes
Option3: Test 3 - 51 votes
I'm using this sql for result:
SELECT options.id, options.value, COUNT(*) as votes FROM votes, options WHERE votes.option_id=options.id AND votes.option_id IN(SELECT id FROM options WHERE ques_id=2) GROUP BY votes.option_id;so i get this: id value votes 1 Test1 83 3 Test3 51 because there is not votes for option Test2 and doesn't show it. i need help to get all data like this: id value votes 1 Test1 83 2 Test2 0 3 Test3 51 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=342944.0 Hi there I never had any php lessons. But I made a site, and now I'm kinda sorta working on a CMS so that someone else can edit the information on the site. Now I was wondering if there was a simple way of displaying all the data from a table, and editing it (not in phpmyadmin). This is my current method; it's rather sloppy but it works like a charm: Code: [Select] mysql_select_db('yourdatabase')or die(mysql_error()); $query = mysql_query("SELECT * FROM activiteit ORDER BY datum"); if(isset($_POST['editActiviteit'])){ $id = mysql_real_escape_string(htmlentities($_POST['id'])); }else{ $id = ''; } echo "<table border='1'><tr><th>Begindatum</th><th>Einddatum</th><th>Titel</th><th>Omschrijving</th><th>Zichtbaar?</th><th>Aanpassen</th><th>Verwijderen</th><th>Voorbeeld</th></tr>"; while($row = mysql_fetch_array($query)){ if($id == $row['id']){ if(empty($row['einddatum'])){ $einddatum = "<input type='text' size='2' name='activiteitDagEind' placeholder='dd' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' placeholder='mm' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' placeholder='jjjj' />"; }else{ $explode = explode('/',$row['einddatum']); $einddatum = "<input type='text' size='2' name='activiteitDagEind' value='$explode[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' value='$explode[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' value='$explode[2]' />"; } $explode2 = explode('/',$row['datum']); $datum = "<input type='text' size='2' name='activiteitDag' value='$explode2[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaand' value='$explode2[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaar' value='$explode2[2]' />"; if($row['actief'] == 0){ $actief = "<select name='actief'><option value='1'>1</option><option value='0' selected='selected'>0</option></select>"; }else{ $actief = "<select name='actief'><option value='1' selected='selected'>1</option><option value='0'>0</option></select>"; } echo "<form action='ward.php' method='post'>"; echo "<tr><td>$datum</td><td>$einddatum</td><td><input type='text' name='activiteitTitel' value='".$row['titel']."' /></td><td><textarea name='activiteitOmschrijving'>".$row['omschrijving']."</textarea></td><td>$actief</td><td><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Slaag op' name='saveActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' name='verwijderActiviteit' value='verwijderen' /></form></td><td><input type='button' disabled='disabled' value='Voorbeeld' /></td></tr>"; }else{ echo "<tr><td>".$row['datum']."</td><td>".$row['einddatum']."</td><td>" . $row['titel'] . "</td><td>" . bbcode_format($row['omschrijving']) . "</td><td>" . $row['actief']."</td><td><form action='ward.php?fx=activiteit' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Pas aan' name='editActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='verwijderen' name='verwijderActiviteit' /></form></td><td><input type='button' value='Voorbeeld' onClick=\"parent.location='ward.php?fx=activiteit&voorbeeld=".$row['id']."'\" /></td></tr>"; } } echo "</table><br /><br />"; I just copy pasted all the code but I'll explain it in big lines: First I open a table. I manually enter a row with the headers. Then every result of the query gets shown in a cell. The last cells of each row contain a delete and an edit button. The delete button deletes that row with the hidden id and reloads the page. When the edit button is clicked, it sends a form with the name of the button, here 'editActiviteit', and the id of the entry. And then the page gets reloaded. When the query is then done again, it checks if $_POST['editActiviteit'] is set, and if it is, it displays input fields with the values in the cells instead of pure text, and a save button instead of a edit button. The system works just fine, but it's heaps of work every time I implement it, for activities, users, ... Also I've been told that table's are not the correct way for displaying results (and they also get a little stretched). How should it be displayed? Thanks in advance. please help me the concept or code to retrive data from the database and display data according to the data from the dynamic list box option. |