PHP - Reading Back From Dynamically Generated Uri
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 Similar TutorialsHey all, Let's say if all of the data in the site is the result of queries from the database that are output as html by php as users interact with the site. For example, there's no home.php file. Rather user clicks the link to view the page, and a php script pulls data from database and renders the page at that time. There is no javascript involved in this process. Would this page be crawlable by google? Thanks for response. Hi All, I have been trying validating radio buttons that were generated dynamically for 2 days now. I can validate when a group of 2 or more than 2 radio buttons are created. But I am unable to validate if a single radio button is generated. So this is where I am generating radio buttons echo "<tr>"."<td class='tablewhitebg'>"."<input type = 'radio' name= 'userid' value= '".$userid. "'></td>"."<td class='tablewhitebg'>$userid</td><td class='tablewhitebg'>$userloginid</td><td class='tablewhitebg'>$fname</td><td class='tablewhitebg'>$surname</td><td class='tablewhitebg'>$locked</td><td class='tablewhitebg'>$mailbox</td><td class='tablewhitebg'>$domainid</td><td class='tablewhitebg'>$timestamp</td><td class='tablewhitebg'>$emailaddress</td><td class='tablewhitebg'>$classofservice</td></tr>\n"; Now this code is generating radio buttons, all is good but when i want to validate it using javascript, Its not working at all <script> function validate_form(thisform) { chosen = ""; len = document.form1.userid.length for (i = 0; i <len; i++) { if (document.form1.userid.checked) { chosen = document.form1.userid.value; } } if (chosen == "") { alert("Please select a record to go ahead!!"); return false; } } </script> Helps please Let's say I have a script that updates the database every 5 minutes. Or fwrites to a text file at an interval. How do I say create a dynamic textbook or label that displays this information and automatically UPDATES on the page without the user clicking on REFRESH? Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. here is the code(I have removed the java script functionalities to reduce length of the post) add_entry2.php Code: [Select] <html> <head> <title>Page Title</title> </head> <body leftmargin="0" topmargin="0"> <!--- forms are good when you wanna actually do stuff ---> <form action="add_entry3.php" name="eval_edit" method="post" format="html"> <table align="center" width = "75%"> <tr> <td align = "center"> Invoice </td> </tr> <tr> <td align = "center"> <!--- very imporant to give the table an id ---> <!--- otherwise it won't know where to edit ---> <table border="1" id="mySampleTable"> <tr> <th>Item No</th> <th>Item Name</th> <th>Item code</th> <th>Description</th> <th>Unit Cost</th> <th>Quantity</th> <th>Price</th> <th>Cancel ?</th> </tr> <tr> <td>1</td> <td><input type="text" name="itemname[]" size="40" maxsize="100"/></td> <td><input type="text" name="itemcode[]" size="20" maxsize="100" /></td> <td><input type="text" name="description[]" size="20" maxsize="100" /></td> <td><input type="text" name="unitcost[]" size="10" maxsize="100" /></td> <td><input type="text" name="quantity[]" size="4" maxsize="100" /></td> <td><input type="text" name="price[]" size="10" maxsize="100" /></td> <td><input type="CHECKBOX" name="cancel[]"/></td> </tr> </table> <table id="totaltbl"> <tr> <th>Total</th> <th>Vat%</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> <td><input type="text" name="total" size="3" maxsize="3" /></td> </tr> </table> <!--- our buttons call our javascript functions when clicked ---> <p> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Calculate Total Amount" onclick="Totalcal();" /> <input type="hidden" name="count" value=""/> <!--<input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="submit" name="submit" value="View Bill" /> <input type="hidden" name="submitted" value="true" /> </p> </td> </tr> </table> </form> </body> </html> ****************************************************8888 This is add_entry3.php Code: [Select] <?php $num=count($_POST['itemcode']); $itemname= $_POST['itemname']; $itemcode = $_POST['itemcode']; $unitcost = $_POST['unitcost']; $description = $_POST['description']; $unitcost = $_POST['unitcost']; $quantity = $_POST['quantity']; $price = $_POST['price']; $problem = FALSE; ?> <h1 align ="center"><b><u>Invoice Details</b></u></h1> <table align="center" width = "75%"> <tr> <td align = "center"> <table border="1" id="mySampleTableheader"> <tr> <td width="75"><b>Item No</b></td> <td width="275"><b>Item Name</b></td> <td width="155"><b>Item code</b></td> <td width="155"><b>Description</b></td> <td width="95"><b>Unit Cost</b></td> <td width="60"><b>Quantity</b></td> <td width="95"><b>Price</b></td> </tr> </table> <?php $i=0; while ($i < $num) { ?> <!--- forms are good when you wanna actually do stuff ---> <form action="save_entry.php" name="eval_edit" method="post" format="html"> <table border="1" id="mySampleTable"> <tr> <td width="75"><?php echo $i+1; ?></td> <td><input type="text" name="itemname[]" value = "" size="40" maxsize="100" readonly/></td> <td><input type="text" name="itemcode[]" value ="<?php echo $itemcode[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="description[]" value ="<?php echo $description[$i]; ?>" size="20" maxsize="100" readonly/></td> <td><input type="text" name="unitcost[]" value ="<?php echo $unitcost[$i]; ?>" size="10" maxsize="100" readonly/></td> <td><input type="text" name="quantity[]" value = "<?php echo $quantity[$i]; ?>" size="4" maxsize="100" readonly/></td> <td><input type="text" name="price[]" value = "<?php echo $price[$i]; ?>" size="10" maxsize="100" readonly/></td> </tr> </table> <?php $i++;} ?> <!--- our buttons call our javascript functions when clicked ---> </td> </tr> </table> <p> <table id="totaltbl"> <tr> <th>Total</th> </tr> <tr> <td><input type="text" name="total" size="20" maxsize="100" /></td> </tr> </table> <input type="button" value="Add Row" onclick="addRow();" /> <input type="button" value="Row count" onclick="countRow();" /> <input type="hidden" name="count" value=""/> <!--<input type="hidden" name="count" value=""/> <input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />--> <input type="button" value="Back" onClick="history.go(-1);return true;"> <input type="submit" name="submit" value="Finalise" /> <input type="hidden" name="submitted" value="true" /> </p> </form> </body> </html> Please, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> 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? 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 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, 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()); 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. 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? 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(); ?> 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 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 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 guys, Im making an event booking/reservation site, I have 5 tables (Malls, Events, Booking, Reservation and Users) which are all connected and doing fine. I created a function which is this... function select_all_events_by_mall_id($mall_id) { echo "<table id='event_table'>"; echo "<th>Event Name</th>"; echo "<th>Event Location</th>"; echo "<th>Number of Cars</th>"; echo "<th>Description</th>"; echo "<th>Booked</th>"; echo "<th>Reserved</th>"; echo "<th>Reserved Until</th>"; echo "<th>Vacant</th>"; $events_set = select_all_events($mall_id); while($events = mysql_fetch_array($events_set)) { echo "<tr>"; echo "<td>" . $events['event_name'] . "</td>"; echo "<td>" . $events['event_location'] . "</td>"; echo "<td>" . $events['number_of_cars'] . "</td>"; echo "<td>" . $events['description'] . "</td>"; // Booked echo "<td>"; $booked_set = select_all_booking($events['id']); while($booked = mysql_fetch_array($booked_set)) { $user_set = select_all_user_booked($booked['users_id']); while($user = mysql_fetch_array($user_set)) { echo $user['company'] . ", " . $user['branch'] . "<br />"; } } echo "</td>"; // Reserved echo "<td>"; echo "<ol>"; $reserved_set = select_all_reservation($events['id']); while($reserved = mysql_fetch_array($reserved_set)) { if(empty($reserved['events_id'])) { echo "No Reservation's "; } else { $reserved_user = select_all_user_reserved($reserved['users_id']); while($user_set = mysql_fetch_array($reserved_user)) { echo "<li>" . $user_set['brand'] . ", " . $user_set['branch'] . "</li>"; } } } echo "</ol>"; echo "</td>"; // Expiration Date echo "<td>"; echo "<ol>"; $reserved_set = select_all_reservation($events['id']); while($reserved = mysql_fetch_array($reserved_set)) { $reserved_user = select_all_user_reserved($reserved['users_id']); while($user_set = mysql_fetch_array($reserved_user)) { $exp_date = select_all_expiration_date($user_set['id']); while($date = mysql_fetch_array($exp_date)) { echo "<li>" . $date['expiration_date'] . "</li>"; } } } echo "</ol>"; echo "</td>"; //Vacant echo "<td>"; $vacant_set = select_all_booking($events['id']); $booking_count = mysql_num_rows($vacant_set); $reserved_count = mysql_num_rows($reserved_set); $total_count = $booking_count + $reserved_count; $vacant = $events['number_of_cars'] - $total_count; if($vacant < 0) { echo "This Event is fully booked"; } else { echo $vacant; } echo"</td>"; echo "</tr>"; } echo "</table>"; } The function starts by receiving an id from picking a mall name from a select tag. It works fine, it outputs the data on the page like i want it to, but my problem is that i need a way to add a submit or any button to each generated row that will, when clicked will insert the event id and user id (who clicked it) to my booking/reservation table as a new row. I tried adding a form inside my function and saving the event id every loop but when i click the submit button i think it doesn't work (or i made a mistake).. Sorry if my coding sucks, I'm kinda new in php. Sorry if its kinda confusing my head is spinning right now from thinking this stuff the whole day.. Thanks in advance for any comments and ideas. |