PHP - Streamlining Dreamweaver Generated Php Code
My learning curve to this point in using php with MySql databases is automatically generated code within Dreamweaver. However, I am sure that it is adding a lot more code than I actually need and I sometimes have 5 or more queries all on one page that are just all the same except that each one has a different ID to reference.
Presumably the best way to do this would be with one query with grouping but as that is still on my list of things to understand I am hoping to tidy things up myself first. For example, two of the queries that I have on one page (http://www.margate-fc.com/content/1st_team/squad.php) are Code: [Select] <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Midfielders = 100; $pageNum_Midfielders = 0; if (isset($_GET['pageNum_Midfielders'])) { $pageNum_Midfielders = $_GET['pageNum_Midfielders']; } $startRow_Midfielders = $pageNum_Midfielders * $maxRows_Midfielders; mysql_select_db($database_Test, $Test);$query_Midfielders = "SELECT * FROM player_season, players, player_positions WHERE player_season.season = '104' AND player_season.player = players.player_id AND player_positions.player_position_id = players.position AND players.position = '3' ORDER BY surname ASC"; $query_limit_Midfielders = sprintf("%s LIMIT %d, %d", $query_Midfielders, $startRow_Midfielders, $maxRows_Midfielders); $Midfielders = mysql_query($query_limit_Midfielders, $Test) or die(mysql_error()); $row_Midfielders = mysql_fetch_assoc($Midfielders); if (isset($_GET['totalRows_Midfielders'])) { $totalRows_Midfielders = $_GET['totalRows_Midfielders']; } else { $all_Midfielders = mysql_query($query_Midfielders); $totalRows_Midfielders = mysql_num_rows($all_Midfielders); } $totalPages_Midfielders = ceil($totalRows_Midfielders/$maxRows_Midfielders)-1; $queryString_Midfielders = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Midfielders") == false && stristr($param, "totalRows_Midfielders") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Midfielders = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Midfielders = sprintf("&totalRows_Midfielders=%d%s", $totalRows_Midfielders, $queryString_Midfielders); header('Content-Type: text/html; charset=ISO-8859-1', true); ?> and Code: [Select] <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Forwards = 100; $pageNum_Forwards = 0; if (isset($_GET['pageNum_Forwards'])) { $pageNum_Forwards = $_GET['pageNum_Forwards']; } $startRow_Forwards = $pageNum_Forwards * $maxRows_Forwards; mysql_select_db($database_Test, $Test);$query_Forwards = "SELECT * FROM player_season, players, player_positions WHERE date_left = '2011-07-01' AND player_season.season = '104' AND player_season.player = players.player_id AND player_positions.player_position_id = players.position AND players.position = '4' ORDER BY surname ASC"; $query_limit_Forwards = sprintf("%s LIMIT %d, %d", $query_Forwards, $startRow_Forwards, $maxRows_Forwards); $Forwards = mysql_query($query_limit_Forwards, $Test) or die(mysql_error()); $row_Forwards = mysql_fetch_assoc($Forwards); if (isset($_GET['totalRows_Forwards'])) { $totalRows_Forwards = $_GET['totalRows_Forwards']; } else { $all_Forwards = mysql_query($query_Forwards); $totalRows_Forwards = mysql_num_rows($all_Forwards); } $totalPages_Forwards = ceil($totalRows_Forwards/$maxRows_Forwards)-1; $queryString_Forwards = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Forwards") == false && stristr($param, "totalRows_Forwards") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Forwards = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Forwards = sprintf("&totalRows_Forwards=%d%s", $totalRows_Forwards, $queryString_Forwards); header('Content-Type: text/html; charset=ISO-8859-1', true); ?> The only difference in the two queries are the query names and the WHERE players.position = 'XX' The way that I see it is that everything below Code: [Select] $currentPage = $_SERVER["PHP_SELF"];is unique to each query but everything above is replicated. Would it work to have all of it between one set of PHP tags with the duplicated code there just once? If so would it simply mean copying everything below '$currentPage = $_SERVER["PHP_SELF"];' in the second query and pasting it just before the '?>' in the first. Also, if anyone is an expert with grouping, I would be more than open to suggestions about setting the page up that way. My head says that it would need a repeat region inside a repeat region to get the data separated the way I want it but my head doesn't often make sense! Thanks in advance Steve Similar TutorialsI could use some help streamlining some Arrays that I shuffled around. Here is my code... Code: [Select] // ************************ // Validate Form Data. * // ************************ foreach($_POST['answerArray'] as $questionID => $response){ // Transfer Data from POST to PHP array. $answerArray[$questionID] = trim($response); if (strlen($answerArray[$questionID]) < 2 || strlen($answerArray[$questionID]) > 1024){ // Invalid Answer. $errors[$questionID] = 'Answer must be 2-1024 characters.'; } }//End of VALIDATE FORM DATA // ****************************** // Attempt to Create Thoughts. * // ****************************** if (empty($errors)){ // Valid form data. // **************************** // Process each Form Field. * // **************************** foreach($answerArray as $questionID => $response){ Before I added the "Validate Form Data" section, this code... Code: [Select] foreach($_POST['answerArray'] as $questionID => $response){ // Transfer Data from POST to PHP array. $answerArray[$questionID] = trim($response); ...was located under the "Process each Form Field" section. I am afraid that this line of code... Code: [Select] foreach($answerArray as $questionID => $response){ ...might be working against the code above?! Isn't there anyway to say "foreach($answerArray[])" and not deal with a Key and Value per se?? Thanks, Debbie I have a submit.php file that includes the following jQuery code: <script> [...] request.done(function( json ) { jQuery('input[name=thumbnail-url]').val(json.thumbnail_url); jQuery('input[name=job_title]').val(json.title); jQuery('textarea[name=htmlcode]').val(json.html); [...] </script> I need to remove jQuery('textarea[name=htmlcode]').val(json.html); and pass the "json.html" value into a PHP variable in another php file (functions.php). The code in the functions.php file is already there. The thing i need to do (and i am seriously struggling with it) is placing the value of json.html into a $phpvariable that i can then call from the function.php file. Do you need any more info for this issue? Thanks. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=355418.0 I'm trying to generate RSS by using PHP and MySQL but I keep getting an error message that I don't know how to solve. Here's the error message: <b>Deprecated</b>: Function mysql_db_query() is deprecated in <b>G:\xampp\htdocs\xampp\dsa\class_rss.php</b> on line <b>32 Here's line 32: Code: [Select] $result = mysql_db_query (DB_NAME, $query, LINK); Here's the entire code from the class: Code: [Select] <? // code followed from http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/ // images sourced: http://www.inyourbasket.com/search/usb-flash-drives/09A?cm_mmc_o=7BBTkw*Vzbp+mwzygt*JmP+4wFByY+mfbgLl*JmP+4wFByY+mfbgL+C+7wEwybg&gclid=CKuGh8DwyKcCFYFB4QodyGRvBg class RSS { // function to include the file which holds global variables. public function RSS() { require_once ('connectvars.php'); } // function derived from both private functions. public function GetFeed() { return $this->getDetails() . $this->getItems(); } // function to connect to the database private function dbConnect() { DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)); } // function to retreive data from the table, and insert between set xml tags which loops through the rows in the table. private function getDetails() { $stick = "stick,"; $location = "location,"; $identification = "identification"; $this->dbConnect($stick, $location, $identification); $query = "SELECT * FROM ". $stick . $location . $identification; $result = mysql_db_query (DB_NAME, $query, LINK); while($row = mysql_fetch_array($result)) { $details = '<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>'. $row['stick.make'] .'</title> <description>'. $row['stick.colour'] . $row['location.street'] . $row['location.town'] . $row['location.city'] .'</description> <image> <url>'. $row['identification.image_url'] .'</url> <width>'. $row['identification.image_width'] .'</width> <height>'. $row['identification.image_height'] .'</height> </image>'; } return $details; } // function to iterate through the table, retreiving data each time and outputting an end result of an RSS structured page. private function getItems() { $stick = "stick,"; $location = "location,"; $identification = "identification"; $this->dbConnect($stick, $location, $identification); $query = "SELECT * FROM ". $stick . $location . $identification; $result = mysql_db_query (DB_NAME, $query, LINK); $items = ''; while($row = mysql_fetch_array($result)) { $items .= '<item> <title>'. $row["stick.make"] .'</title> <description><![CDATA['. $row["stick.colour"] .']]></description> </item>'; } $items .= '</channel> </rss>'; return $items; } } ?> Could anyone help me out here? Thanks On a website currently under development the URL does not change when navigating around on the page. It always displays the root URL. This is the script that should generate the links: $URLvars=substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],"/")+1); $vatLink=$URLvars; $thisPageURL=$_SERVER["PHP_SELF"]; if(strpos($thisPageURL, "secure/locktech/")!==false)$thisPageURL=substr($_SERVER["PHP_SELF"], 16); $prodLink="http://www.lock-tech.co.uk".$thisPageURL; It used to. However, the server has changed and it does not any more. Is it maybe because the 2 paths (http://www.lock-tech.co.uk and secure/locktech/) must be changed according to the new server? Does anyone know what exactly do these paths stand for? I understand that one of them is the root path but what does the path in the line Code: [Select] if(strpos($thisPageURL, "secure/locktech/")!==false)$thisPageURL=substr($_SERVER["PHP_SELF"], 16); stand for? I have something like this on one of my pages: $name = 'Bob'; Code: [Select] if ((isset($_POST['name'])) || ($_POST['name'] == '')) { $name = $_POST['name']; //update database } echo '<form action='' method='POST'>'; echo '<table><tr><td width="125">Name: </td><td><input type="text" name="signature" style="width: 270px;" value="' . $name . '" /></td></tr></table>'; echo '</form>'; Here's the problem: Initially, because the form data has not been sent the input box says: 'Bob'. If I remove the name Bob from the input box by manually clicking in it and deleting the name, and I submit the form, it keeps showing 'Bob', whereas I would like it to be empty. What am I doing wrong? Ok, so I currently have this http://pastebin.com/cCgyavs0 snippet that generates links to the previous, next and last page based on the current page (GET variable) or the total item count in the MySQL DB to then use forms as links by inserting the URLs into the action attribute. I did this cause I don't wanna use images as links, btw :P It kinda works - I get links like: shop.php?page=1 shop.php?page=12 shop.php?page=14 shop.php?page=225 When I'm on page 13 of 225 for example. Though when I click one of the buttons, I always get redirected to "shop.php?". :/ Hi, I am trying to get some charecters to display properly in emails that are sent via a form on my site. The finnish characters ä and ö come out as squares when viewed in Outlook. I have tried various encoding types such as UTF-8 and Western European (dreamweaver), both as the script encoding and as the encoding in the mail() function. $body = 'Sähköposti:' ; mail($salesEmail, "Call Back Request", $body, "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\nFrom: $salesEmail") ; = 'S�hk�posti:' or just squares in Outlook. I have also tried hard coding them as ä and ö and the symbol literals to no effect. Does anyone know what is causing this? I'm not sure of the appropriate subject line for this feature, but hopefully I'm close. I'll try to describe what I'm trying to do. The most common place you see this is on web based file uploads so I'll use it as my example. Let's say I want to allow my user to upload files so there is a text box where they enter the file name. The user is allowed to upload as many files as he wants with 1 push of the submit button. Upon the loading of the form, there will be 5 textboxes for file upload, but if the user wants to upload more than 5 files, there is a link that is clicked and I think via ajax or javascript another textbox will be added. The user can do this for as many files he wants to upload. This is what it looks like to the user, but then when the form is submitted how are these variables referenced? So how is this setup in the main form and how are the variables referenced after form submission? If anyone can point me to a good web tutorial on this type of thing I would appreciate it. Thanks Carl Hey all, I have a relationship where a zone has many posts and a category has many zones but a zone can also have many categories. The zones are basically parts of a page, such as the main area and sidepanel stored in database as records with name fields such as 'panel' and 'main'. There's a serious flaw right now and I would like to know the best solution to address it. Right now I access the posts of a zone of a category like this: Code: [Select] $category->zone->get()->post->get(); The above ends up displaying all the posts in the database for any given category because when category is selected, it searches for the associating zones, and then selects all posts related to those zones, which is wrong. i want to select all posts of the zones associated with that particular category. Current database: Code: [Select] posts id zone_id zones id name categories_zones id zone_id category_id categories id What should I do? Add a category_id column to the posts table and relate the post directly to the category as well as directly to the zones table so the post table would have two foreign keys: category_id and zone_id Would this be the most effective thing to do given my requirements? Thanks for response. I'm wanting to make a sitemap for my website but as it's quite big there are a lot of url's I need to include. I was wondering if anyone know's of a way this can be done using PHP. e.g. using PHP to generate a list of URL's. I had a think myself but wasn't sure how to do it. Thanks for any help. I currently have a query that compiles a League Standings Table (the full code is below) and generate the ranking with Code: [Select] @rownum := @rownum+1 AS rank This works fine for the main standings page but I want to use the row numbers elsewhere. Each team has it's own page which uses 'team.team_id' as its 'recordID'. On these pages I would like to show that particular teams ranking in the standings. The two options I see would be to run the query filtering by 'team.team_id' but that would only return the one record so ranking would always be '1' or run the whole query and then somehow find which ranking relates to 'team.team_id' (something that may be possible with VIEWS but the database is running on MySQL4) but I cannot figure out how to get around this. For example, if the standings were Rank Team 1 Rovers 2 United 3 City 4 Rangers 5 Town 6 Athletic 7 Wanderers 8 Hotspur On the 'Rangers' page I would want it to show 'RANKING: 4' and on the 'Athletic' page it would show 'RANKING: 6'. On top of this I would want to show a small version of the rankings with one team above and one team below (it would actually be two teams but I will keep it simple until I understand it!) so one again given the two examples above I would get RANGERS PAGE Rank Team 3 City 4 Rangers 5 Town ATHLETIC PAGE Rank Team 5 Town 6 Athletic 7 Wanderers The query is $i = 1; $ht = "g.home_team = t.team_id"; $at = "g.away_team = t.team_id"; $hw = "g.home_goals > g.away_goals"; $aw = "g.home_goals < g.away_goals"; $d = "g.home_goals = g.away_goals"; $hg ="g.home_goals"; $ag ="g.away_goals"; $table = mysql_query("SELECT t.team_name as Tm, @rownum := @rownum+1 AS rank , (sum(CASE WHEN (".$ht." AND ".$hw.")OR(".$at." AND ".$aw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$ht." OR ".$at.") AND ".$d." THEN 1 ELSE 0 END)) AS P , (sum(CASE WHEN (".$ht." AND ".$hw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$ht.") AND ".$d." THEN 1 ELSE 0 END)) AS HP , (sum(CASE WHEN (".$at." AND ".$aw.") THEN 3 ELSE 0 END) + sum(CASE WHEN (".$at.") AND ".$d." THEN 1 ELSE 0 END)) AS AP , count(CASE WHEN (".$ht." OR ".$at.") THEN 1 ELSE 0 END) as GP , sum(CASE WHEN (".$ht." ) THEN 1 ELSE 0 END) as HGP , sum(CASE WHEN ".$at." THEN 1 ELSE 0 END) as AGP , sum(CASE WHEN (".$ht." AND ".$hw.") OR (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS W , sum(CASE WHEN (".$ht." AND ".$hw.") THEN 1 ELSE 0 END) AS HW , sum(CASE WHEN (".$at." AND ".$aw.") THEN 1 ELSE 0 END) AS AW , sum(CASE WHEN (".$ht." AND ".$d.") OR (".$at." AND ".$d.") THEN 1 ELSE 0 END) AS D , sum(CASE WHEN (".$ht." AND ".$d.") THEN 1 ELSE 0 END) AS HD , sum(CASE WHEN (".$at." AND ".$d.") THEN 1 ELSE 0 END) AS AD , sum(CASE WHEN (".$ht." AND ".$aw.") OR (".$at." AND ".$hw.") THEN 1 ELSE 0 END) AS L , sum(CASE WHEN (".$ht." AND ".$aw.") THEN 1 ELSE 0 END) AS HL , sum(CASE WHEN (".$at." AND ".$hw.") THEN 1 ELSE 0 END) AS AL , SUM(CASE WHEN (".$ht.") THEN ".$hg." WHEN (".$at.") THEN ".$ag." END) as GF , SUM(CASE WHEN (".$ht.") THEN ".$hg." END) as HGF , SUM(CASE WHEN (".$at.") THEN ".$ag." END) as AGF , SUM(CASE WHEN (".$ht.") THEN ".$ag." WHEN (".$at.") THEN ".$hg." END) as GA , SUM(CASE WHEN (".$ht.") THEN ".$ag." END) as HGA , SUM(CASE WHEN (".$at.") THEN ".$hg." END) as AGA , (SUM(CASE WHEN (".$ht.") THEN ".$hg." WHEN (".$at.") THEN ".$ag." END) - SUM(CASE WHEN (".$ht.") THEN ".$ag." WHEN (".$at.") THEN ".$hg." END)) as GD , (SUM(CASE WHEN (".$ht.") THEN ".$hg." END) - SUM(CASE WHEN (".$ht.") THEN ".$ag." END)) as HGD , (SUM(CASE WHEN (".$at.") THEN ".$ag." END) - SUM(CASE WHEN (".$at.") THEN ".$hg." END)) as AGD from teams t left join all_games g on t.team_id in (g.home_team,g.away_team) WHERE comp = '1' AND home_goals IS NOT NULL AND date BETWEEN '2010-07-01' AND '2011-06-31' GROUP BY t.team_id ORDER BY P desc, GD desc, GF desc The html is Code: [Select] <table width="" border="0" cellpadding="0" cellspacing="0" BORDER=1 RULES=ROWS FRAME=BOX> <tr> <td></td><td></td> <td colspan="9" align="center" bgcolor="#00FF99">ALL</td> <td colspan="9" align="center" >Home</td> <td colspan="9" align="center">Away</td> </tr> <tr> <td class="hdcell" >POS</td> <td class="hdcell" >Team</td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> <td width="30" class="hdcell"></td> <td></td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> <td></td> <td width="30" class="hdcell">P</td> <td width="30" class="hdcell">W</td> <td width="30" class="hdcell">D</td> <td width="30" class="hdcell">L</td> <td width="30" class="hdcell">F</td> <td width="30" class="hdcell">A</td> <td width="30" class="hdcell">GD</td> <td width="30" class="hdcell">Pts</td> </tr> <?php while ($row_table = mysql_fetch_assoc($table)){ echo '<tr> <td style="text-align:left" width="30">'.$i.'</td>'; echo '<td style="text-align:left">'.$row_table['Tm'].'</td> <td style="text-align:left">'.$row_table['GP'].'</td> <td style="text-align:left">'.$row_table['W'].'</td> <td style="text-align:left"> '.$row_table['D'].'</td> <td style="text-align:left"> '.$row_table['L']. '</td> <td style="text-align:left"> '.$row_table['GF']. '</td> <td style="text-align:left"> '.$row_table['GA']. '</td> <td style="text-align:left"> '.$row_table['GD']. '</td> <td style="text-align:left"> '.$row_table['P']. '</td> <td style="text-align:left"></td> <td style="text-align:left"></td> <td style="text-align:left">'.$row_table['HGP'].'</td> <td style="text-align:left">'.$row_table['HW'].'</td> <td style="text-align:left">'.$row_table['HD'].'</td> <td style="text-align:left"> '.$row_table['HL']. '</td> <td style="text-align:left"> '.$row_table['HGF']. '</td> <td style="text-align:left"> '.$row_table['HGA']. '</td> <td style="text-align:left"> '.$row_table['HGD']. '</td> <td style="text-align:left"> '.$row_table['HP']. '</td> <td style="text-align:left"></td> <td style="text-align:left">'.$row_table['AGP'].'</td> <td style="text-align:left">'.$row_table['AW'].'</td> <td style="text-align:left">'.$row_table['AD'].'</td> <td style="text-align:left"> '.$row_table['AL']. '</td> <td style="text-align:left"> '.$row_table['AGF']. '</td> <td style="text-align:left"> '.$row_table['AGA']. '</td> <td style="text-align:left"> '.$row_table['AGD']. '</td> <td style="text-align:left"> '.$row_table['AP']. '</td> </tr>'; $i++; } ?> </table> As always, thanks in advance for any tips or suggestions, even if they are telling me to scrap what I have so far and start again!! Steve PS. Can someone explain why @rownum := @rownum+1 AS rank causes $i to increment by one? I found the code while searching and do not understand why $i is necessary unless it is a reserved reference. The way the code looks, I should be able to output the ranking using 'rank' but that does not work. I have no problem with how it does things, it would just be nice to understand! Hello I've spent the last few hours writing a small php file that creates a signature for Steam (a gaming platform) and saves it as a png. It basically just pulls the neceassary info and images from the user's Steam XML stream and uses GD to arrange it nicely. A link to an example is here. Now, the trouble I have is that it saves the image as a .php file (it can be downloaded as a png but not linked to as one, images.php.png doesn't exist). I can navigate to the webpage and save as a png but for obvious reasons can't link to it as an image (making the forum signature part kind of hard to pull off). Is there any easy way (I'm unspeakably bad with php) that I can save the php graphic as a PNG to an external page (for example /sig_name.png or /images.php?id=name.png)? Thanks for any help My PHP code is generating XML with a blank first line before the <?xml version="1.0" ?> see http://urbanbees.co.uk/maps/phpsqlajax_genxml3.php I have been told this is the reason why my map is not showing the markers in chrome and FF but it is OK in IE8. see http://urbanbees.co.uk/maps/map_of_hive_locations_update.htm You'll either see markers or not depending on your broswer. How do I change the code to not generate this first blank line. Here is the php code. <?php require("phpsqlajax_dbinfo.php"); // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("markers"); $parnode = $dom->appendChild($node); // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error());} // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $dom->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute("name",$row['name']); $newnode->setAttribute("address", $row['address']); $newnode->setAttribute("lat", $row['lat']); $newnode->setAttribute("lng", $row['lng']); $newnode->setAttribute("type", $row['type']); } echo $dom->saveXML(); ?> Hi. I have a rating site where users fill in a name of what they are rating, comments about it and a rating and submit it to my database. I then have another page which shows all of these entries but only the name and overall rating using php. What I want is for users to click on the name and it take them to a separate page which displays all the comments and ratings for that item. As users can add items to rate I cant set up a page for each manually so was wondering how to do it dynamically. Everything i throw into google leads me in the wrong direction though. If someone could point me to a good tutorial or give me an idea about what to search id be very grateful. Cheers. Hi Mates, I want to know how to create auto generated pages in submit button with the existing templates...Wordpress users may easily understand what actually i mean...i am using the code that is creating a page but not getting the desired page name and giving a blank page that is without any formatting... Code: [Select] <?php $content = <<<EOL <head> </head> <body> New page EOL; include ('config.php'); mysql_select_db("$db_name"); $result = mysql_query("SELECT * FROM text ORDER BY ID") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo $row['title']; echo "<br />"; } $content .= <<<EOL </body> </html> EOL; $file = '$result' . '.php'; $open = fopen($file, "w"); fwrite($open, $content); fclose($open); ?> Hi, I have a question here. Currently my $tutor_id is auto incremental in my SQL, and it is in running numbers. However I will like to add a 'T' in front of the id. Example: Currently, our id number is 1 2 3 4 etc. Would like to achieve T1 T2 T3 T4 etc. How do I do it? Below is my code as well. Please kindly advise. Thanks /**INSERT into tutor_id table to create a new id for new tutors**/ $query = "INSERT INTO tutor_id (id) " . "VALUES ('$id')"; $results = mysqli_query($dbc, $query) or die(mysqli_error()); $tutor_id = mysqli_insert_id($dbc); /**INSERT into tutor table**/ $query1 = "INSERT INTO tutor (tutor_id, email) " . "VALUES ('$tutor_id', '$email')"; $results1 = mysqli_query($dbc, $query1) or die(mysqli_error()); Hello guys, I want to make an xml feed into my webpage, but the xml is generated from an .asp file on another website, so it's not actually an xml file, but xml output. Now, I want to retrieve this xml output on my webpage, but I'm having difficulties while doing this. What I've tried so far: - With PHP: Code: (php) [Select] <?php echo file_get_contents("http://link-on-other-website.asp?XML=1"); ?> - With javascript: Code: (javascript) [Select] <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://link-on-other-website.asp?XML=1", false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("RECORD"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("DATE")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> When using the PHP code, I can retrieve it obviously, but I get an <?xml ... > declaration within my body, which is not allowed. When using the Javascript code, I can't even retrieve anything. And the goal is to style this xml output to match my website. That's the whole purpose of this xml link, because I couldn't style the iframe I had earlier. Can someone help me on this, on how to properly embed this asp generated xml output, within my HTML5 document? ps: I've asked for the xml-feed link from that other website, so using the above PHP code is legit in my case. This question is PHP and javascript/jQuery so I wasn't sure where to post it, but anyway... Here is the code I am using so far. Currently it just displays a larger version of the image in a new window. I would like a lighbox instead. I have tried this with "FancyBox" but couldn't get it to work on all the images, just the first one. Any suggestions? Code: [Select] <?php //GET PRODUCT VAR etc. ^^ $directory = "Images/items/$product/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); $imgone = $images[0]; $gallery = ''; foreach($images as $image) { $tn = explode("/", $image); $tnname = $tn[3]; $gallery .= '<a href="#" rel="'.$image.'" class="image" title="Images/items/'.$product.'/large/'.$tnname.'" alt="'.$product.'"><img src="Images/items/'.$product.'/thumbs/'.$tnname.'" class="thumb" border="1" style="margin-bottom:7px;"/></a> '; } if(is_dir("Images/items/".$product)){ $gallery .= "<div id='image' class='bigimg' align='left'>"; $gallery .= '<a href="largeimg.php?id='.$product.'&i=Images/items/'.$product.'/large/0main_img.jpg" target="_new"> <img src="Images/items/'.$product.'/0main_img.jpg" border="0" alt='.$name.'/> <span class="more"><img src="Images/zoom.png" /></span></a></div>'; } ?> <!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><?php echo $name; ?></title> <script type="text/javascript" src="js/ddsmoothmenu.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <link href="CSS/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="CSS/ddsmoothmenu.css" /> </head> <body> <div class="hidden"> <script type="text/javascript"> $(function() { $(".image").click(function() { var image = $(this).attr("rel"); var large = $(this).attr("title"); var product = $(this).attr("alt"); $('#image').hide(); $('#image').fadeIn('slow'); $('#image').html('<a href="largeimg.php?id='+ product +'&i=' + large + '" target="_new"><img src="' + image + '"/><span class="more"><img src="Images/zoom.png" /></span></a>'); return false; }); }); </script> what follows is a simplified version of what i'm attempting to do. say i have a mysql table called 'pages', that looks roughly like this: Code: [Select] id parent label 1 0 home 2 0 about 3 0 events 4 2 history 5 2 philosophy 6 3 past-events 7 3 future-events 8 6 past-event-gallery which uses the parent key as a self-referencing index. items with parent=0 don't have a parent - all other items refer to rows in the same table. so, 'about' has 2 children: 'history' and 'philosophy'. this can extend an unlimited number of levels in depth. e.g., 'past-event-gallery' has a parent of 'past-events' which has a parent of 'events'. building it out is pretty straightforward - start with all rows that have a parent of 0, then recurse... Code: [Select] select id, label from pages where parent=0 // grab the id... select id, label from pages where where parent={$id} etc. which works (for example) to build out a uri for an <a> tag's href attribute. the problem arises when trying to go backwards... i'm trying to get back the id of the row from that example uri... so if the output was 'events/past-events/past-event-gallery', i'm exploding on slashes to get the component parts, and want to walk it back to get the id of the row. if the label keys were unique, it'd be simple enough... select id from pages where label={$label} but labels might be duplicated. for example, 'past-events' might have a child called 'gallery', but it might be possible that 'about' also has a child called 'gallery', etc. it might even occur several levels deep, so i need to walk it backwards until i've determined the correct id from the component parts of the URI. my initial thought was to run from left-to-right, something like: Code: [Select] while(count($parts) > 0){ $component = array_shift($parts); $result = mysql_query("select id from pages where label='{$component}'"); // this is where i lose it... maybe create a temp table from the results and continue...? } or maybe from right-to-left... Code: [Select] while(count($parts) > 0){ $component = array_pop($parts); $result = mysql_query("select id from pages where label='{$component}'"); $row_count = mysql_num_rows($result); switch($row_count){ case 1 : // this is the only one with that label, so return the ID and be done break; case 0 : // no labels match, so return a 404 or missing item or something and be done break; default : // if there are more than 1 matching labels, figure out which one - here is where i get lost on this approach... break; } } also considered a self-returning function for the second (right-to-left) idea, but didn't get far with it. any ideas? i could be (probably am) totally off on both approaches mentioned, and there might be a much easier way to do this. i'd be happy to hear any suggestions... tyia |