PHP - Dynamic Rows
Im working on a site and particularly the photo gallery section. I want to display 9 images on 3 rows (3 per row).
And im stuck. Te only way i can get the images to show up not one on top of the other is by using a table. but how can i tell the table to only put 3 <td>'s then to <br> Heres my code so far... <?php $sql_images = mysql_query("SELECT * FROM photos ORDER BY upload_date DESC LIMIT 9"); while($row = mysql_fetch_array($sql_images)){ $photo_id = $row["id"]; $location = $row["location"]; $display_pics .= ' <td width="125px"> <a href="image.php?id='. $album_id .'" class="black"><img src="images/uploads/thumbs/' . $location . '" /></a> </td>'; } ?> Then to display it ... Code: [Select] <table width="top" cellpadding="10" cellspacing="20"> <tr> <?php echo $display_pics; ?> </tr> </table> My goal is to do it as simple as possible! Can anyone help? If you don't think tables are the way to go im open to any suggestions. I've thought about <divs> but then the images show up one on top of the other and not beside each other. By the way all the images are a max of 100px heigh and 100px wide Thanks for any help or suggestions! Similar TutorialsHey guys, I got another one that i could use some help on. I have a input form that utilizes a javascript that adds additional rows to my table. here is a look at what i got. Code: [Select] <script type="text/javascript"> function insertRow() { var x = document.getElementById('results_table').insertRow(-1); var a = x.insertCell(0); var b = x.insertCell(1); var c = x.insertCell(2); var d = x.insertCell(3); var e = x.insertCell(4); a.innerHTML="<input type=\"text\" name=\"id\">"; b.innerHTML="<input type=\"text\" name=\"place\">"; c.innerHTML="<input type=\"text\" name=\"username\">"; d.innerHTML="<input type=\"text\" name=\"earnings\">"; e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">"; } function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('results_table').deleteRow(i); } </script> this is my code stored in the header of my page. basically just a button to add a new row and a button in each row to delete rows if needed. here is a look at my html table, pretty basic... Code: [Select] <table id="results_table"> <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th> <tr> <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td> </tr> </table> Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database. is this doable? the structure of my database is: ResultID (Primary Key) Place Earnings UserID (Foreign Key) EventID (Foreign Key) now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. so when it comes to processing I need to do a switch of these two things before I run my query. Should something like this work? Code: [Select] $username = $_POST['username']; $userID = "SELECT userID FROM users WHERE username="$username"; $query = mysql_query($userID); also i've never tried to submit multiple entries at a time. maybe i have to create an array somehow in order to capture each rows data. any thoughts? as always thanks for the help. Hi, I'm trying to build a 'simple' page to improve a process where I work.
I'm wanting to do this.
Read either the last line, the last 10 lines, or something I decide on from a log and display the output in table rows and columns.
I've done this before with loops and db query's, but don't know how to approach it using php only as this is the first time I'm using it.
So right now I have this in a table but it will only display one row.
<tr><td colspan="5"> what Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. I have 2 queries that I want to join together to make one row
Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete $sql = "SELECT * from updates ORDER BY id DESC LIMIT 3"; $stmt = $link->prepare($sql); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows = '0') { echo "There haven't been any updates yet."; } else { echo "There are news posts"; }
Gives me the error "Cannot write property in /home/evoarena/public_html/Dev/news.php:14 ", line 14 is the if statement. How can I fix it? I Have a page that will display the data that was posted into a database, but it displays it like this: id logoname locationname address city state zip phone website etc... I want to display the data like this: id <--- this will repeat records 4 columns across logoname locationname etc... id <--- this will repeat records 4 columns across logoname locationname etc... and then repeat similar for the rest of the data. Sorry Im a n00b, but trying. Here is the current code: <?php include "config.php"; $con = mysql_connect("$dbhost","$dbusr","$dbpass"); if (!$con) { die('Could not connect:'. mysql_error()); } mysql_select_db("$dbname",$con); $q="select * from venues"; $result=mysql_query($q); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<table border='0'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td></td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> Help would be greatly appreciated and an explanation so that I don't have to keep asking Can any one tell me whats the best ( actually error free ) which i can use to count the number of rows finally resulting after select command. I use this ... Code: [Select] $sql = mysql_query("select * from usname where name1='$name1' and name2='$name2' and amm='$amm'"); $num=mysql_num_rows($sql); echo $num; But it always gives the same error.... and the error is.......... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\insert.php on line 20 where line 20 is... Code: [Select] $num=mysql_num_rows($sql); - Pranshu Agrawal pranshu.a.11@gmail.com im wondering how to get php to read the latest row (instead of show them all) and when another one comes it replaces it once the page refreshes Hello I have a table that inserts a new row with data when a member views a page. I wish to count all the rows for each member, and then be able to show what the cuurent members "position" is eg. what members has the highest row count. Example. counting the rows for member_A returns 1000 rows, the number of rows for member_B returns 1500 rows. How can I display for member_A that he is in "second" place? can someone please give me some guidance on how to do this please I am wanting to create a status updating type application on my site and i have this idea in my head i want it to retrive and print the last 3 posts (max ids) made by the user if someone could give me some example code please and i can hopefully work from that. Thanks James Hi guys I have a problem. I limit the displayed rows by 10 (which works) and then a link saying "next" or "previous" The link itself works, but the site always just displays teh first 10 data entries. What do I do wrong? Thank you! Code: [Select] <?php $host="****"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id ORDER BY school_name LIMIT 0, 10"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <?PHP //check if the starting row variable was passed in the URL or not if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { //we give the value of the starting row to 0 because nothing was found in URL $startrow = 0; //otherwise we take the value from the URL } else { $startrow = (int)$_GET['startrow']; } ?> <?PHP //this part goes after the checking of the $_GET var $fetch = mysql_query("SELECT * FROM sp_users,sp_schools where sp_users.user_id=sp_schools.school_id LIMIT $startrow, 10")or die(mysql_error()); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } #Layer1 { position:absolute; left:803px; top:36px; width:65px; height:28px; z-index:1; } #Layer2 { position:absolute; left:707px; top:19px; width:143px; height:39px; z-index:1; } #Layer3 { position:absolute; left:247px; top:463px; width:175px; height:53px; z-index:2; } --> </style> <title>User overview</title> </html> <div id="Layer2"> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="foo" value="<?= $foo ?>" /> <input type="submit" name="submit" value="Refresh" /> </form></div> <div id="Layer3"><?PHP //now this is the link.. echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>'; ?> <?PHP $prev = $startrow - 10; //only print a "Previous" link if a "Next" was clicked if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>'; ?></div> <table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users / Total: <?php echo $num_rows ?></strong></div></td> </tr> <tr> <td width="342" align="center"><span class="style2">school</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> Hi ,im face little problem in duplicating rows. it's not easy task wht i need: i got this rows right now id----------position-------------A_Q_ID 1---------------1--------------------5----- 2---------------2--------------------5----- 3---------------3--------------------5----- 4---------------1--------------------6----- 5---------------2--------------------6----- 6---------------3--------------------6----- what i need is to duplicat all the rows and have them inserted after the rows i allready have like that: id------------position-------------A_Q_ID 7-----------------1--------------------7----- 8-----------------2--------------------7----- 9-----------------3--------------------7----- 10---------------1--------------------8----- 11---------------2--------------------8----- 12---------------3--------------------8----- i tryed few ways without success . any idea how to do that please? i cannot get the logic on doing it thanks Hi ive got this code which echos out all the rows from an SQL table. while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['subject1'] . "</td>"; echo "<td>" . $row['subject2'] . "</td>"; echo "<td>" . $row['subject3'] . "</td>"; echo "<td>" . $row['subject4'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "</tr>"; } echo "</table>"; All i want to do is add all the 4 subject together and echo it out. simple but not sure how to do it. any ideas please? Thanks Matt Hi, having stopped php for a while, i'm a little rusty, can someone help me - instead of the results returning in a row by row format, can i have it so it returns column by column? so, rather than result 1 being first, then 2 underneath then 3 etc etc, can i have result 2 next to result 1? heres my code $result = mysql_query("SELECT * FROM members ORDER BY member_id DESC") or die(mysql_error()); echo "<table border='2'>"; echo "<tr> <th></th> <th></th> <th></th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row[printf('<img src="%s" height="96" width="128" style="border: 0" />', $row['profile_pic_short'])]; echo "</td><td>"; echo "<a href=\"PHP-Login/advert_pages/view_profile_specific.php?seller_name=$row[login]\">". $row['login'] . "</a>"; echo "</td></tr>"; } echo "</table>"; ?> all help appreciated thanks " SELECT event.*, epr1.participantId AS team_1, epr1.participantRoleId AS team_1_role, epr2.participantId AS team_2, epr2.participantRoleId AS team_2_role FROM bb_EventParticipantRelation epr1, bb_EventParticipantRelation epr2, bb_Event event WHERE event.parentId='".$leage_type."' AND epr1.id != epr2.id AND epr1.parentParticipantId = '0' AND epr2.parentParticipantId = '0' AND epr1.eventId=event.id AND epr2.eventId=event.id ORDER BY epr1.participantRoleId ASC, event.startTime, team_1, team_2 ASC " This sql gets 2 rows and combines them as one, it does work but the issue is it seems to be taking too long in loading the page also I just need some advice on a better version Thank you On my site, I currently have a page that lists my team's fixtures: http://www.cfrclunj.co.uk/fixtures.php As can be seen, in between each separate month there is a row of blank, grey cells. I am now updating the site so that it takes all information from a database (for easier update). On my test page (at bottom) I have recreated the fixtures table using my db: http://www.cfrclunj.co.uk/db_test.php What I am wondering is if there is any way to get the grey monthly separater row into my table. Could this be done by inserting a row of data into the db table that uses an if statement to change it's appearance? Or could I somehow use MYSQL/PHP to make it put a row in for each separate month? I have to admit my PHP and MYSQL skills are still at a very basic level, and so any help would be great! Hi guys, I want to count the number of rows in a table and want to display them. However that field stays empty. Everythign else works. What do I do wrong? Code: [Select] <?php //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="25" align="center"><span class="style2">No.</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="342" align="center"><span class="style2">school</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['num_rows']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> ...I'm Australian, hence the 'u' in coloured, in case you're wondering! Basically I'd like to create a table of results for a running race that has rows shaded pink if the participant is female. I think my problem is something to do with not declaring 'sex' as a variable, but I'm not really sure how to do this. My code is below. Any advice would be much appreciated. Code: [Select] <?php $dbcnx = @mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('coast2ko_test')) { exit('<p>Unable to locate the results ' . 'database at this time.</p>'); } $sql = mysql_query("SELECT * FROM result_single ORDER BY place ASC"); echo "<table border='1' CELLPADDING=5 STYLE='font-size:13px'>"; echo "<tr> <td><H3>First name</h3></td> <td><H3>Lastname</H3></td> <td><H3>Sex</H3></td> <td><H3>Time</H3></td><td><H3>Place</H3></td></tr>"; // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($sql)) { // Print out the contents of each row into a table if ($sex=="F") echo "<tr bgcolor='#FF99FF'>"; else echo "<tr>"; echo "<tr bgcolor='#FF99FF'>"; echo "<td>"; echo $row['firstname']; echo "</td><td>"; echo $row['lastname']; echo "</td><td>"; echo $row['sex']; echo "</td><td>"; echo $row['time']; echo "</td><td>"; echo $row['place']; echo "</td></tr>"; } echo "</table>"; ?> |