PHP - X Y Coordinate Grid, Using Php With Data In Sql
Hello all:
Let me give you some background, over the past 10 years I have dealt with many forums, and even built some limited PHP scripts myself for various things related to those forums. Usually modifications to expand the forums abilities. So I had thought I had a fairly good handle on PHP in general... LOL, that is until recently when I decided to take on a slightly different/larger challenge. Recently one of my forum users requested the creation of a X,Y Coordinate grid, where they could put into it certain bits of information and it would return showing them the X,Y location of thier various work attached in some way shape or form to his site. I had thought this would be a simple project, as I have worked with GD image creation before, as well as SQL statements many times, it simply should have been a blending of my exsisting knowledge into one program. While this was a unique challenge for me, its one I seem to have been unable to plug. I have searched the web extensively the last 2 weeks hoping to find a tutorial, and sadly while I can find a great many related to bar graphs and line graphs, I can't seem to find a single one related to a simple X Y coordinate graph, yet I know I have seen them done many times. I am at a total loss on this one and so far my attempts have garnered me 0 results. I can't even create a 20 x 20 grid with any success... LOL. I am hoping one of you would be kind enough to post a tutorial, with a simple code that would produce a grid using GD, or even some other form of image generation, with 1 - X Y plot in it generated either from SQL or from the program its self, so that I could see a working version and with luck go from there to expand it to my needs. Thank you. Similar TutorialsHow do I create a coordinate map in php? I created ordered pairs and I want to plot them on a grid. Grid is about 200000x200000. Need help in achieving a data entry grid. I have two tables am_user (idam_user, name) and am_activity (idam_act, act) with the data Data for am_user is 1, John 2, Mary 3, Kate Data for am_activity is 1, Cooking 2, Cleaning 3, Painting I have a third table that stores the role played by each user for the activities. am_role (idam_role, role) 1, Manage 2, Observe 3, Documents I want my User table to be my header, Activity table to my 1st column and Role table to populate the data grid John Mary Kate Cooking Manage Document Observe Cleaning Document null Manage Painting Observe Document Manage By putting two while loops I am able to generate the header and 1st column but I need help in populating the grid in between. Also I want my data entry area (rows and column besides header and 1st column) to have lookup where they can select values from the am_role table. So, John can "Manage" "Painting" tomorrow if he wants to The two while loops are Code: [Select] $query = "select idam_user, Name "; $query .= " from am_user "; $result = mysql_query($query) or die(mysql_error()); // display data in table echo "<center>"; echo "<table>"; echo "<tr>"; echo "<th></th>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<th>' . $row['name'] . ' '; echo "</th>"; } echo "</tr>"; $query = "select idam_act, act "; $query .= " from am_activity "; $result = mysql_query($query) or die(mysql_error()); // display data in table // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<tr>'; echo '<td>' . $row['act'] . '</td>'; echo '</tr>'; } // close table> echo "</table>"; echo "</center>"; Please advise if this thought is realistic and how can I achieve it. Thanks in anticipation. 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! Hey folks! I am looking to build a small adventure game in PHP and the key to this will be a 3x3 (or possibly bigger) grids of squares, with the user situated in the centre. I therefore need to be able to figure out the co-ords of the surrounding squares. Presumably I will need to define the size of the master grid, then using the co-ords of the current square (defined from a database containing the users location), calculate the co-ords for the surrounding 8 grid squares. Has anyone had any experience with this? Where should I start? (Maths isn't my strong point tbh, but I can pick things up quickly) Thanks in advance! EDIT - in case it wasn't too clear, the "world map" would be something like 1000x1000 squares, but the player can only see the 3x3 grid at there location. I want to pull the last 8 entries from a database. Code: [Select] $result = mysql_query("SELECT * FROM `sites` ORDER BY id DESC LIMIT 8"); The problem is when I ORDER BY ASC the elements are displayed fine but in ORDER BY DESC the are messed up. Why? and how do I fix it ORDER BY DESC ORDER BY ASC CSS Code: [Select] html { font-family: segoe ui, arial, helvetica, sans-serif; height: 100%; overflow: hidden; } body { background-image: linear-gradient(bottom, #FFFFFF 16%, #E8E8E8 79%); background-image: -o-linear-gradient(bottom, #FFFFFF 16%, #E8E8E8 79%); background-image: -moz-linear-gradient(bottom, #FFFFFF 16%, #E8E8E8 79%); background-image: -webkit-linear-gradient(bottom, #FFFFFF 16%, #E8E8E8 79%); background-image: -ms-linear-gradient(bottom, #FFFFFF 16%, #E8E8E8 79%); background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.16, #FFFFFF),color-stop(0.79, #E8E8E8)); background-repeat: no-repeat; } #sites { width: 56%; padding: 10px; position: relative; left: 50%; margin-left: -29%; top: 150px; } .siteWidget { margin: 5px; padding: 10px; width: 200px; float: left; text-align: center; -webkit-transition: all 0.25s ease-in-out; -moz-transition: all 0.25s ease-in-out; } .siteWidget .img { height: 150px; -moz-box-shadow: 2px 2px rgba(0,0,0,0.25); -webkit-box-shadow: 2px 2px rgba(0,0,0,0.25); box-shadow: 2px 2px rgba(0,0,0,0.25); margin-bottom: 10px; } .siteWidget .img:hover { box-shadow: 0 0 10px rgba(0, 0, 0, 1); -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 1); -moz-box-shadow: 0 0 10px rgba(0, 0, 0, 1); } a { text-decoration: none; colour: black; } a:visited { color: black; } a:hover { color: #e90000; } h3 { margin: 0; padding: 0; } html/PHP Code: [Select] <? ob_start(); include('config.php'); ?> <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Site Selector</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php if (!isset($_POST['submit'])) { ?> <form action="index.php" method="post"> <table> <tr> <td> <h3>Add New Site: </h3> </td> <td> <input type="text" name="siteName" placeholder="Name" /> </td> <td> <input type="text" name="siteUrl" placeholder="URL" /> </td> <td> <input type="submit" name="submit" value="Add Site" /> </td> </tr> </table> </form> <div id="sites"> <?php //load the pages from the Database $result = mysql_query("SELECT * FROM `sites` ORDER BY id ASC LIMIT 8"); if (mysql_num_rows($result) == 0) { echo 'No entries'; } else { while ($row = mysql_fetch_assoc($result)) { ?> <div class="siteWidget"> <div class="img"><a href="http://<?=$row['url']?>"><img src="http://pagepeeker.com/t/m/<?=$row['url']?>" border="0"></a></div> <a href="http://<?=$row['url']?>" name="<?=$row['name']?>"><?=$row['name']?></a> </div> <? } } } else { //Get the data $siteName = secure($_POST['siteName']); $siteUrl = secure($_POST['siteUrl']); if (!$siteName || $siteUrl) { header("Location: index.php"); } else { $query = mysql_query("INSERT INTO `sites` (name, url) VALUE($siteName, $siteUrl)"); if (mysql_num_rows($query)) { header("Location: index.php"); } else { echo 'Site not Added!<br />'; echo '<a href="index.php">Go Back</a>'; } } } ?> <div style="clear:both;"></div> </div> </body> </html> HTML ONLY Code: [Select] <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Site Selector</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <form action="index.php" method="post"> <table> <tr> <td> <h3>Add New Site: </h3> </td> <td> <input type="text" name="siteName" placeholder="Name" /> </td> <td> <input type="text" name="siteUrl" placeholder="URL" /> </td> <td> <input type="submit" name="submit" value="Add Site" /> </td> </tr> </table> </form> <div id="sites"> <div class="siteWidget"> <div class="img"><a href="http://google.ca"><img src="http://pagepeeker.com/t/m/google.ca" border="0"></a></div> <a href="http://google.ca" name="Google">Google</a> </div> <div class="siteWidget"> <div class="img"><a href="http://facebook.com"><img src="http://pagepeeker.com/t/m/facebook.com" border="0"></a></div> <a href="http://facebook.com" name="Facebook">Facebook</a> </div> <div class="siteWidget"> <div class="img"><a href="http://coldcallradio.com"><img src="http://pagepeeker.com/t/m/coldcallradio.com" border="0"></a></div> <a href="http://coldcallradio.com" name="Cold Call Radio">Cold Call Radio</a> </div> <div class="siteWidget"> <div class="img"><a href="http://redbarradio.net"><img src="http://pagepeeker.com/t/m/redbarradio.net" border="0"></a></div> <a href="http://redbarradio.net" name="Red Bar Radio">Red Bar Radio</a> </div> <div class="siteWidget"> <div class="img"><a href="http://youtube.com"><img src="http://pagepeeker.com/t/m/youtube.com" border="0"></a></div> <a href="http://youtube.com" name="YouTube">YouTube</a> </div> <div class="siteWidget"> <div class="img"><a href="http://coldcallradio.com/wp-admin"><img src="http://pagepeeker.com/t/m/coldcallradio.com/wp-admin" border="0"></a></div> <a href="http://coldcallradio.com/wp-admin" name="Cold Call Radio Admin Panel">Cold Call Radio Admin Panel</a> </div> <div class="siteWidget"> <div class="img"><a href="http://apple.ca"><img src="http://pagepeeker.com/t/m/apple.ca" border="0"></a></div> <a href="http://apple.ca" name="Apple Canada">Apple Canada</a> </div> <div class="siteWidget"> <div class="img"><a href="http://trios.com"><img src="http://pagepeeker.com/t/m/trios.com" border="0"></a></div> <a href="http://trios.com" name="triOs College">triOs College</a> </div> <div style="clear:both;"></div> </div> </body> </html> How i can create alphabetic grid . like on this website http://www.vietnamworks.com/jobseekers/search.php Hi, I'm not too sure how to word this, but what I want to is to have a timetable for the 7 days of the week and 24 hours of the day, which gives 100-200 possible combinations. A user will select a checkbox and click submit which will then upload to a mysql database with the respective information. My question is, is there a way that the check box will dynamically select the day and time based on the row and column in it, as opposed to having 168 different names and values for each checkbox? I hope I have made my point succinctly but please post back if any more info is needed. Ta. Trying to figure out my game map. Here is what's going on: Any player can view themself on the map and also the user at this location: x:50, y50. For some reason the map will not show anyone else. If you would like to see it, just go to http://www.gglegends.net/map.php and login with the credentials below (only 1 user can be logged in at a time): Credential for Demo Account - (I have restricted areas that affect others gameplay and areas that change the demo account) Username: demo Password: pass Other map locations to try out: x:60, y:60 x:19, y:79 x:98, y:72 x:75, y:51 x:97, y:26 x:66, y:12 Here is the complete code to my map: <?php require 'includes/header.php'; //Check to see if user exists in the map table, if not redirect location to get coordinates $user_map_check_results = $db->query ("SELECT * FROM map WHERE uID=".$user['uID'].""); $user_map_check = mysql_num_rows($user_map_check_results); if ($user_map_check == 0){ echo '<META HTTP-EQUIV="Refresh" Content="0; URL=firstrun.php">'; die(); } //Fetch the largest x coordinate in the map table. $map_size_x_result = $db->query( "SELECT MAX(x) AS map_max_x FROM map" ); $map_size_x = $db->fetch( $map_size_x_result ); //Fetch the largest y coordinate in the map table. $map_size_y_result = $db->query( "SELECT MAX(y) AS map_max_y FROM map" ); $map_size_y = $db->fetch( $map_size_y_result ); //Set map size. Determined by largest x and y coordinates. $grid_x = (int)$map_size_x['map_max_x']; $grid_y = (int)$map_size_y['map_max_y']; //x and y rows to display at a time. $display_rows = (int)10; //Fetch all user locations. $users_map_result = $db->query( "SELECT * FROM map LEFT JOIN users ON map.uID=users.uID" ); $users_map = $db->fetch( $users_map_result ); //Fetch user map location from database. $user_location_result = $db->query( "SELECT * FROM map LEFT JOIN users ON map.uID=users.uID WHERE map.uID=".$user['uID']."" ); $user_location = $db->fetch( $user_location_result ); //default display coordinate if none specified - will be user map location. $x = (int)$user_location['x']; $y = (int)$user_location['y']; $param_x = $_REQUEST["xcord"]; $param_y = $_REQUEST["ycord"]; if (isset($param_x) && isset($param_y)) { //validate that the parameter is a legit point. if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) { $x = (int)$param_x; $y = (int)$param_y; } } //set map location to the center of the map. $display_half = round($display_rows / 2); $other_half = $display_rows - $display_half; //display the target in the middle. $start_x = ($x - $display_half) +1; $end_x = $x + $other_half; //if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1. if ($start_x < 1) { $start_x = 1; $end_x = $display_rows; } else //if $end_x is off the grid we have to compensate and add the remaining rows to the start. if ($end_x > $grid_x) { $extra = $end_x - $grid_x; $end_x = $grid_x; $start_x = $start_x - $extra; } //same applies for the y axis. $start_y = ($y - $display_half) +1; $end_y = $y + $other_half; //if the $start_y variable is less than 1 the grid would be in the negatives. so set it to 1. if ($start_y < 1) { $start_y = 1; $end_y = $display_rows; } else //if $end_y is off the grid we have to compensate and add the remaining rows to the start. if ($end_y > $grid_y) { $extra = $end_y - $grid_y; $end_y = $grid_y; $start_y = $start_y - $extra; } ?> <b><tl>World Map</tl></b><br /> <img alt="" src="images/seperator.gif" /><br /> Click anywhere on the map to begin moving around. You can click on players name's to view their profile.<br /><br /> Move to Map Location or <a href="map.php"><u>Return to base</u></a>. <?php echo "Current Map Coordinates: X $x - Y $y"; ?><br /> <!-- Search custom coordinates --> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="GET"> <input name="xcord" type="text" size="3" maxlength="2" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''" value="x"> <input name="ycord" type="text" size="3" maxlength="2" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''" value="y"> <input type="submit" value="Submit"> </form> <br /><br /> <!-- Show map --> <table width="750" cellspacing="0" cellpadding="1" border="0"> <?php //these 2 for loops represent the y and x axis //using the data collected above the loops will properly display the grid. for ($Ty = $start_y; $Ty <= $end_y; $Ty++) { //start new row echo '<tr>'; for ($Tx = $start_x; $Tx <= $end_x; $Tx++) { //show grid DisplayGrid($Tx,$Ty); } echo '</tr>'; } ?> </table> <?php //Function to disaply the map. function DisplayGrid($grid_x,$grid_y) { global $x, $y, $user_location, $users_map; $bgimg = 'grass.gif'; $building = ''; if ($grid_x == $user_location['x'] && $grid_y == $user_location['y']) { $building = '<img src="images/map/building.gif" alt="" border="0" /><br />'; $user_map_name = '<br /><a href="player_profile.php?id='.$user_location['uID'].'" target="_blank"><u><b>'.$user_location['uLogin'].'</b></u></a><br />'; } if ($grid_x == $users_map['x'] && $grid_y == $users_map['y']) { $building = '<img src="images/map/building.gif" alt="" border="0" /><br />'; $user_map_name = '<br /><a href="player_profile.php?id='.$users_map['uID'].'" target="_blank"><u><b>'.$users_map['uLogin'].'</b></u></a><br />'; } echo "<td width=\"75\" height=\"75\" style=\"background-image: url('images/map/$bgimg');background-repeat: repeat;\" align=center valign=center onclick=\"window.location.href='map.php?xcord=$grid_x&ycord=$grid_y'\">$building $user_map_name</td>"; } require 'includes/footer.php'; ?> hi trying to make a grid of two columns , data from db using mysqli and php, but it does not work...can you guys help me thanks in advance
<?php echo"<table border='0' align='center' cellpadding='2' cellspacing='2' width='70%'>";
$query = "SELECT * FROM posts";
while ($row = mysqli_fetch_assoc($select_all_categories_query)){
if($count ==0) { echo"<tr>"; }
echo"<div class='post-img'>"; }else { $count=0;
echo"<div class='post-img'>"; } $count++; } echo"</tr></table>"; ?>
this is the result
i want this kind of result
thank you Hi, I've been trying to figure out a way to create a very large (1000x1000) grid. With each cell being 5x5, so 200 rows and 200 cols. Here is the way I've been doing it: <? $col = 1; while ($col <= 200) { echo("<ul style=\"width: 1000px; height: 5px; border: 0px; margin: 0px; padding: 0px;\">"); $row = 1; while ($row <= 200) { $c1 = "#ffcc00"; $c2 = "#ffff99"; $c3 = "#cfeef6"; $c4 = "#b2ebc5"; $c5 = "#ffffff"; $c6 = "#d7ebff"; $c7 = "#dfceb9"; $c8 = "#b3ccc5"; $number = rand(1,8); $bgcolour = ${"c$number"}; echo("<li style=\"background-color: $bgcolour; width: 5px; height: 5px; float: left; display: inline;\"></li>"); $row = $row + 1; } echo("</ul>"); $col = $col + 1; } ?> It work's, however, as you can imagine it is incredibly slow loading. And browsers such as IE usually end up crashing, even on high end, fast processing PC's, let alone what might happen on an average house hold computer. I've been wondering if there is a more effective method of creating the grid that I am unaware of, I will also be implementing hover boxes (overLib) over each 5x5 cell, which will display dynamic information from a database. And the background color will also be taken from the database and not be decided by the php rand(); like it currently is. So I'm thinking once I start adding more to it, it's going to run even slower than what it is now. I know this is a PHP forum, but if PHP isn't the best answer would anyone think Javascript could make it run smoother? Or is it going to be impossible to create it fast and efficiently no matter what I use? After days of agony, I finally figured out a way to display my blog posts masonry style.
However, I now want to find out if I can make it look exactly (or close to) the static design that I had before which is this :
http://pier36nyc.com/events/
How my dynamic masonry looks like right now on my localhost:
http://postimg.org/image/uy5jb4zax/
This is the code for the masonry:
<script> This might be a bit hard to explain! I have a grid, 32x32 which is actually 1024 mySQL rows in a table, you can see the table he http://interbitlotto.com/grid each cell is a row in the database, top left is ID 1, bottom right is id 1024. get it? right well its a battle ship game, and im stuck on the automatic battle ship placement script. I have displayed the generated boats as misses so we can see them. The problem i am having, is that the random number generater chooses a cell too close to the side so the boat ends up wrapping to the other side. I cant think of a way to detect if its going to wrap, if it is then choose another cell... The code below chooses the orientation of the boat, then chooses a random cell... but as you can see, no code for "across" to stop it choosing one too close to the side. Any ideas? Code: [Select] $orientation = rand(1,2); //get random orientation - 1 = down, 2 = across. if ($orientation == 1){ $multiply = 32; //cells till next row $max = 1024 - (32 * $boatlength); //prevents it from choosing a cell too close to the bottom $startcell = rand(1,$max); }else{ $multiply = 1; //across, so next cell $max = 1024; $startcell = rand(1,$max); } I don't want to use AI, or a primary key to sort the data, as it could create some problems if the items are visited out of order, but I want to sort it always based upon a single element for speed.
I'm creating a table that will be populated (built), when it's corresponding entry doesn't exist, how do I get it sorted out if someone visits 2, then 7 before they visit 5 to read what's there? It's not a 2d number line, but a 3d number grid.
Edited by Q695, 09 September 2014 - 11:30 PM. Code: [Select] <?php $path = "../assets/tattoos/"; $path2 = "../assets/tattoos-thumbs/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlink($path. "/" . $file) or die("Failed to delete file"); unlink($path2. "/" . $file) or die("<meta http-equiv=\"refresh\" content=\"0; url=index.php\" />"); } } ?> <form name="form1" method="post"> <?php $imageDir = "../assets/tattoos/"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<img src='../assets/tattoos/$file' style='height:auto;width:8%;' alt='$file'>"; } closedir($dir_handle); ?> <input type="submit" name="Delete" value="Delete"> </form> I have this code, which calls an image directory and adds a checkbox next to it, you check the boxes you wish, hit delete and the pictures are removed from the server. I need them to display in a grid view, like 4 columns by X amount of rows. Any help would be greatly appreciated. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=327455.0 Am new here - looks like a great foru! I would sincerely appreciate any help anyone can give me. I have been trying to solve my problem for hours and I am not having any luck, so I thought I would post and see if anyone can help. I am very stuck and am not making much progress on this project, and I am certain the answer is very simple. I am constructing a form to collect data for a specialized purpose. The form and program actually work for its intended function, but I am trying to enhance the user experience by preventing customers from having to reenter all of their data should there be a problem with any of the data submitted. I have been able to do that with the contact form portion, but what I am having trouble with is the portion which has as many as 400 possible entries. So, in a nutshell, if the customers contact data is incomplete or in error, the form will ask them to return to the page and correct things. The previous data entered has been saved in the session and the input value will equal the previous entry. i.e. <tr> <td align="right" class="infoBox"><?php echo ENTRY_EMAIL_ADDRESS; ?></td> <td align=left><?php echo "<input type=text name='cemail' value=\"$cemail\" size=35 maxlength=35>" ?></td> </tr> Works perfectly, all well and good there. On the other 400 more or less entries, I am having a difficult time tweaking the string concatenation to work to achieve similar results. There are 4 columns each with $points entries asking for a dimension in either feet or inches. The <input name=> is one of ptaf,ptai,ptbf,ptbi, appended programatically with the corresponding row number or data point. i.e. "ptaf1", "ptai1", etc... This is produced by the example below and works perfectly also. <?php { $points=100; $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" name="ptaf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>A' .$i . ' (in) <input type="text" name="ptai'.$i.'" size=4 maxlength=4> </td> <td align="right" NOWRAP>B' .$i . ' (ft) <input type="text" name="ptbf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>B' .$i . ' (in) <input type="text" name="ptbi'.$i.'" size=4 maxlength=4> </td> '; $i++; } } ?> I am trying to add <input value=$ptai.$i> for each field but as I mentioned I am not having any luck. It seems as if I have tried every combination imagineable, but still no luck. My head is spinning! The closest I seem to have gotten was with this: <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="' . "$ptaf" . $i . '" ></td> But line 17 for example returns this: <input type="text" value="17" name="ptaf17" maxlength="3" size="6"> To recap, I am trying to have the value set to whatever the customer may have entered previously. Again, I would most appreciate any help anyone can give me. If you need clarification on anything please let me know. Thanks AJ Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance This could be PHP or MySql so putting it in PHP forum for now... I have code below (last code listed) which processes a dynamically created Form which could have anywhere from 0 to 6 fields. So I clean all fields whether they were posted or not and then I update the mySQL table. The problem with this code below is that if, say, $cextra was not posted (i.e. it wasnt on the dynamically created form), then this code would enter a blank into the table for $cextra (i.e. if there was already a value in the table for $cextra, it gets overwritten, which is bad). What is the best way to handle this? I'm thinking i have to break my SQL query into a bunch of if/else statements like this... Code: [Select] $sql = "UPDATE cluesanswers SET "; if (isset($_POST['ctext'])){ echo "ctext='$ctext',"; } else { //do nothing } and so on 5 more times.... That seems horribly hackish/inefficient. Is there a better way? Code: [Select] if (isset($_POST['hidden']) && $_POST['hidden'] == "edit") { $cimage=trim(mysql_prep($_POST['cimage'])); $ctext=trim(mysql_prep($_POST['ctext'])); $cextra=trim(mysql_prep($_POST['cextra'])); $atext=trim(mysql_prep($_POST['atext'])); $aextra=trim(mysql_prep($_POST['aextra'])); $aimage=trim(mysql_prep($_POST['aimage'])); //update the answer edits $sql = "UPDATE cluesanswers SET ctext='$ctext', cextra='$cextra', cimage='$cimage', atext='$atext', aextra='$aextra', aimage='$aimage'"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } Here's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. |