PHP - Auto Generating Php Pages In Relation To Auto_increment
My question is basically this:
If I'm building a submission form - which places info into my DB via a mySQL query (INSERT INTO) - is there also a way to reference the id that it is creating? The form is set to just dump raw data into a database - each submission enters data into at least 8 DB tables which are all tied together by an $id row in each table. My query references those $id rows in each table to build a query. After each query is completed, a unique url (which is stated by the submitter in the form of /example/someotherword/) is generated. I need to find a way to place some sort of script within a page that displays the results based on each $id. So, lets say that the url is clicked, it would take you to a page that displays the results - but only does so based on the reference to that urls unique $id within the table. I'll provide code once I get home, but if you guys have any ideas that would be great. Similar TutorialsHello, I want to create a custom user profile, by allowing admin to add them from admin panel then users can fill their values. How can I create such system ? Thanks. I am creating a drink recipe site. So far I have created the mysql table and the page where i can enter in the drink name ingredients ect. and it inserts into the table. Could some one point me in the right direction where when I make an entry into this table a new page is created from the content. How would I go about doing this? Hi, so i kinda planned to code a new project.
But i'm not quite sure about this.
I could imagine you could pull the pages out.
So let me explain.
So i believe google is generating these numbers automatically and automatically linking it to a page.
Is there a way to do that easily? Would help me alot.
30b3096a003f946c870b24e6f93538d7.png 4.72KB
0 downloads
So if i have 50 result per page.
Thats the thing i want!
If 50 result = > then new page!
And then it should create a new number down there.
=)
Any questions?
ASK ME!
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); ?> I am putting title in my URL whenever a new auto generated page is generates, so if i use single word tile then it is fine but when there is more that two words in the title it shows space in every word and therefor in title too. how can i add this hyphen or any other special char to my URL so it would look like? i.e. If i use title to MY FIRST WEB PAGE.php, what should i do so i can make it like MY-FIRST-WEB-PAGE.php Hello, how can i reset Auto_increment to 0? because i've made some tests with my database and now may entrys start from value 19.. how can i have 2 AUTO_INCREMENT colloums ? i need my id column and my position column to Auto increment. i cant use the id column to set my position as i need to change the val and as i no u cant change ur prim key auto increment column ???? so any forts how i can get a drop down list box to show the content of column `position` (in format 1,2,3,4,5,6,7ect ) and auto increment when adding a new project. my idea when adding is to get the form page to read the bottom of the `position` column for the number and then add one and set that val to a read only text field on the project add page. is there an easy or better way to do this and how would one go about doing this ??? as im a noobie but getting there how-tos or code samples will help a lot people and im wanting to learn as well so any good php tutorial sites send them ,my way thanks Ohhh, these thoughts just run through my head as I sleep. But will it work? Can I set a function so that my UPDATE form will NOT execute after a certain DATE (or even a time of day?) I'm thinking something along the lines of: $time=timestamp if $time>19:00 echo" You need to make changes before 7:PM"; else (UPDATE... yadda yadda yadda) Yes, i know this is worse than a rough draft, but will it work? Is it acceptable methodology? I have a database table of plants, one of chemicals, one of products, one of illnesses. Each table is connected, for example lets say opium poppies. They contain the chemical morphine. Morphine is used in painkiller products. Its used to treat pain and other illnesses. On the opium poppy page, I want to list all the chemicals found in the poppy. All the products (i.e. opium, laudanum) made from the poppy. All the illnesses which are treated with the poppy. Users need to be able to edit this page, and enter chemicals, products or illnesses that are related to this plant. They also need to be able to edit the info on the page.
Making database relations is a pain in the ass with CakePHP. I don't want to waste any more time so I'm thinking maybe making it as a wordpress plugin is the way to go. How would you go about this? Is there an easier way than wordpress, like a better CMS, or framework? If I use wordpress, should I do all the DB interactions with AJAX to avoid having to interact with the DB through wordpress (this gave me massive trouble in the past since I had my data in an external db)?
i have two tables, employee details table(empno, emp_name , branch) and attendance table(date, Ot, attendence). I want to create a relation between two tables //php code <?php include_once('con.php'); if(!empty($_GET['search'])) { $search = $connect->prepare('SELECT * FROM posts WHERE title LIKE :search'); $search->bindValue(':search', '%'.$_GET['search'].'%', PDO::PARAM_STR); $search->execute(); ?> <?php while($row = $search->fetch()) {?> <li class="result" onClick="searchValue('<?php echo $row['title'];?>')"><?php echo $row['title'];?></li> <?php } ?> <?php } ?> //ajax $('#inputsch').keyup(function(){ $.ajax({ type: 'GET', url: 'fetch.php', data:'search='+$(this).val(), success: function(data){ $('#box').show(); $('#box').html(data); } }); }); }); function searchValue(val) { $('#inputsch').val(val); $('#box').hide(); } //search box <form action="search.php"> <input id="inputsch" type="text" name="search" placeholder="search..." autocomplete="off" autofocus> <button type="submit" value="search" >search</button> </form> <div id="box"></div> //the problem here is when i click the result is only added to input, but i want it to autosubmit
So a project I have simply to learn how it is done is to make an auto updating sitemap with a auto submitter. I have been doing a little research on sitemaps but haven't found much in the way of a tutorial or white paper or similar, anyway I was wondering if I am on the right track or not. What I was thinking for the auto-updating sitemap is since site maps are XML, when an article is published using my custom CMS/Blogging system, I make it rewrite the sitemap appending the new URL that will be generated. Then for the auto-submit, I can either make it a cron job or just manual press, but it would go though a for list of URLs, replacing the end part with my site map url. I think that is how it would be done. If you have a better idea, or can point out an article so I can understand a lot more with sitemaps, I will appreciate it, I am trying to learn as much as possible, I have gone to the offical website (sitemaps.org) but it doesn't have what I am looking for. Thanks, James There is a section in my site in which i will need to give the user 3 options: Generate Specific User Text As: 1. pdf 2. .doc 3. .txt 4. print in html The 4th option is simple. The other three are completely new to me. I know little bit about fopen, fwrite and fclose, however these are commands that write files to the server. I need to write files to the users computer. Is the best way for this to be: 1. the user clicks .txt 2. the .txt is written to the server 3. the .txt is then downloaded to the users computer by the user 4. the .txt is then deleted from the server All 4 steps to be done with one click from the user. Might there not be traffic problems if lots and lots of users are doing this at the same time? Any pushes in right direction here would be great, there seems to be hundreds of sites saying different solutions hi guys, im trying to resize and save a thumbnail version of images uploaded to my site in a sub folder (thumbs). I've currently got: $image=imagecreatefromjpeg($filepath); list($width, $height) = getimagesize($filepath); $new_width = 200; $new_height= 150; $image_p=imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Save the image imagejpeg($image_p, '/thumbs'.$filepath); // Free up memory imagedestroy($image_p); but it appears to do nothing, but it also doesn't return any errors? could someone help me out please? thanks! Does anyone know of a free php library to create pdf417 2d barcodes? As a complete newbie, I'm not sure Ive got the terminology right in my subject header. But this is what I am trying to do. I have a soccer stats site with data entered into each of numerous 'seasons', accessible via a drop-down menu, as he http://www.fleethistory.co.uk/stats/matches.php Now regardless of what season I select, the URL will stay the same as above. What I want to do is have users go direct to a particular season from a link without having to use the drop-down. How would I generate a unique URL for each of the seasons listed in the drop-down? Don't know if you need the PHP code, but here it is just in case: Code: [Select] <?php /* *************************************************************************** * tplSoccerStats * ----------------------------------------------------------------------- * Copyright: TPL Design * email: info@tpl-design.com * www: www.tpl-design.com/tplsoccerstats *************************************************************************** */ // Starts a new session or resumes the current one. session_start(); // Get db host, db username, db password, and db name from admin/user.php // (each team has its own db). include('admin/user.php'); // Establish db connection. Select appropriate team db. $connection = mysql_connect("$host", "$user", "$password") or die(mysql_error()); mysql_select_db("$txt_db_name", $connection) or die(mysql_error()); // Get preferences stored in db. $sql = "SELECT * FROM tplss_preferences WHERE ID = '0'"; $pref = mysql_query($sql, $connection) or die(mysql_error()); $pdata = mysql_fetch_array($pref); mysql_free_result($pref); // Include php preferences. include('preferences.inc'); // Use session defaults if available, otherwise set them from database values. if ((!isSet($_SESSION['defaultseasonid_tplss'])) || (!isSet($_SESSION['defaultmatchtypeid_tplss'])) || (!isSet($_SESSION['defaultlanguage_tplss']))) { $_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID']; $_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID']; $_SESSION['defaultlanguage_tplss'] = $pdata['DefaultLanguage']; } $defaultseasonid = $_SESSION['defaultseasonid_tplss']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_tplss']; $defaultlanguage = $_SESSION['defaultlanguage_tplss']; // Include language based global vars, in our case english, e.g. $txt_preview = 'Preview' include('language.inc'); // Include pafc banner and menu bar. include('header.php'); // Start an html form. echo '<form method="post" action="change.php">' . "\n"; // Print images at top of form if we have them (we don't). $image_url = "images/header.jpg"; $image_url2 = "images/header.gif"; if(file_exists($image_url) || file_exists($image_url2)) { echo '<table align="center" width="' . $tb_width . '" cellspacing="0" cellpadding="0" border="0">' . "\n"; echo "<tr>\n"; echo '<td align="center">' . "\n"; if (file_exists($image_url)) { echo '<img src="' . $image_url . '" ALT=""><br>' . "\n"; } elseif (file_exists($image_url2)) { echo '<img src="' . $image_url2 . '" ALT="">' . "\n"; } echo "</td></tr></table>\n\n"; } ?> <!-- Print change bar table --> <table align="center" width="<?php echo $tb_width ?>" cellspacing="0" cellpadding="0" border="0" bgcolor="<?php echo $border_c ?>"> <tr> <td> <table width="100%" cellspacing="1" cellpadding="5" border="0"> <tr> <td bgcolor="<?php echo $inside_c ?>" align="center"> <?= $txt_change ?>: <select name="season"> <option value="0"><?= $txt_all ?></option> <?php $sql = "SELECT * FROM tplss_seasonnames WHERE SeasonPublish = '1' ORDER BY SeasonName DESC"; $get_seasons = mysql_query($sql, $connection) or die(mysql_error()); while($data = mysql_fetch_array($get_seasons)) { if($data['SeasonID'] == $defaultseasonid) echo '<option value="' . $data['SeasonID'] . '" SELECTED>' . $data['SeasonName'] . "</option>\n"; else echo '<option value="' . $data['SeasonID'] . '">' . $data['SeasonName'] . "</option>\n"; } mysql_free_result($get_seasons); ?> </select> or Competition: <select name="matchtype"> <option value="0"><?= $txt_all ?></option> <?php $sql = "SELECT * FROM tplss_matchtypes ORDER BY MatchTypeName"; $get_types = mysql_query($sql, $connection) or die(mysql_error()); while($data = mysql_fetch_array($get_types)) { if($data['MatchTypeID'] == $defaultmatchtypeid) echo '<option value="' . $data['MatchTypeID'] . '" SELECTED>' . $data['MatchTypeName'] . "</option>\n"; else echo '<option value="' . $data['MatchTypeID'] . '">' . $data['MatchTypeName'] . "</option>\n"; } mysql_free_result($get_types); ?> </select> <input type="submit" name="submit" value="Select"> </td> </tr> </table> </td> </tr> </table> <!-- Print outer fixture tables --> <table align="center" width="<?php echo $tb_width ?>" cellspacing="0" cellpadding="0" border="0" bgcolor="<?php echo $border_c ?>"> <tr> <td> <table width="100%" cellspacing="1" cellpadding="5" border="0"> <tr> <td bgcolor="<?php echo $inside_c ?>" align="center"> <!-- Print inner fixture table --> <table width="<?= $tb2_width ?>%" cellspacing="0" cellpadding="4" border="0"> <tr> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Date</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>H/A</b></font> </td> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Opponent</b></font> </td> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Competition</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818" colspan="2"> <font color="#FFffff"><b>Result</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Att</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Details</b></font> </td> </tr> <?php // Construct db query to get fixtures from database. $selectClause = "SELECT M.MatchID AS id, M.MatchAdditionalType AS additype, O.OpponentName AS opponent, O.OpponentID AS oppid, M.MatchGoals AS goals, M.MatchGoalsOpponent AS goals_opponent, M.MatchPenaltyGoals AS penalty_goals, M.MatchPenaltyGoalsOpponent AS penalty_goals_opponent, M.MatchOvertime AS overtime, M.MatchPenaltyShootout AS penalty_shootout, DATE_FORMAT(M.MatchDateTime, '%M %Y') AS month, DATE_FORMAT(M.MatchDateTime, '%a %e') AS date, DATE_FORMAT(M.MatchDateTime, '%H:%i') AS time, M.MatchPlaceID AS place, M.MatchAttendance AS att, M.MatchPublish AS publish, MT.MatchTypeName AS typename, P.PreviewText AS prewtext FROM ( tplss_matches M, tplss_matchtypes MT, tplss_opponents O ) LEFT OUTER JOIN tplss_previews P ON M.MatchID = P.PreviewMatchID "; if (($defaultseasonid != 00) && ($defaultmatchtypeid != 0)) { $whereClause = "WHERE M.MatchTypeID = '$defaultmatchtypeid' AND M.MatchSeasonID = '$defaultseasonid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid == 0) && ($defaultmatchtypeid != 0)) { $whereClause = "WHERE M.MatchTypeID = '$defaultmatchtypeid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid != 0) && ($defaultmatchtypeid == 0)) { $whereClause = "WHERE M.MatchSeasonID = '$defaultseasonid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid == 0) && ($defaultmatchtypeid == 0)) { $whereClause = "WHERE M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } $orderByClause = "ORDER BY M.MatchDateTime"; // Execute query. $sql = $selectClause . $whereClause . $orderByClause; $get_matches = mysql_query($sql, $connection) or die(mysql_error()); // Loop round fixtures (which come back from database in date order). while($data = mysql_fetch_array($get_matches)) { // Print a month header row each time we hit a new month. if ($data['month'] <> $lastMonth) { echo "<tr>\n"; echo '<td align="left" valign="middle" bgcolor="#7c0606" colspan="9">'; echo '<font color="#FFffff"><b>' . $data['month'] . "</b></font>"; echo "</td>\n"; echo "</tr>\n\n"; $lastMonth = $data['month']; } // Assign home/away based vars. if ($data['place'] == 1) { $placeBg = $bg4; $venue = "H"; } else { $placeBg = $bg3; $venue = "A"; } // Print date and venue. echo"<tr>\n"; echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; echo $data['date']; echo "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">'; echo $venue; echo "</td>\n"; // Print opponent team name (as a link if possible). echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; if ($data['oppid'] == 1) { echo '$data[opponent]'; } else { echo '<a href="opponent.php?opp=' . $data['oppid'] . '">' . $data['opponent'] . "</a>"; } echo "</td>\n"; // Print competition type. echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; echo $data['typename']; if ($data['additype'] != '') { echo " / " . $data['additype']; } echo "</td>\n"; // Print result, attendance and match report. if ($data['goals'] == NULL || $data['goals_opponent'] == NULL) { // No goals recorded - match can't have been played yet - print empty fields. echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">'; if ($data['prewtext'] == '') { echo " "; } else { echo '<a href="preview.php?id=' . $data['id'] . '">' . $txt_preview . "</a>"; } echo "</td>\n"; } else { // Goals recorded - figure out result and score - print required fields. if ($data['penalty_goals'] == NULL || $data['penalty_goals_opponent'] == NULL) { if ($data['goals'] > $data['goals_opponent']) $result = '<img src="images/win.jpg">'; elseif ($data['goals'] < $data['goals_opponent']) $result = '<img src="images/lose.jpg">'; else $result = '<img src="images/draw.jpg">'; $score = $data['goals'] . " - " . $data['goals_opponent']; } else { if ($data['penalty_goals'] > $data['penalty_goals_opponent']) $result = "<b>W</b>"; else $result = "L"; $score = $data['goals'] . " - " . $data['goals_opponent'] . " (" . $data['penalty_goals'] . " - " . $data['penalty_goals_opponent'] . ")"; } echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $result . "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $score . "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $data['att'] . "</td>\n"; if($data['publish'] == 1) { echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '"><a href="matchdetails.php?id=' . $data['id'] . '">Yes</td></a></td>' . "\n"; } else { echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '"> </td></a></td>' . "\n"; } } echo "</tr>\n\n"; } // Free resultset. mysql_free_result($get_matches); ?> </table> </td> </tr> </table> </td> </tr> </table> <?php // Print tpl soccers stats message. include('bottom.txt'); ?> </form> <?php // Finish off html. include('footer.php'); ?> Hi, I've written some code to take information from an SQL database and write it out in the RSS format (Although it doesn't validate). The problem is i'd like the page to have the .rss (or .xml) file extension, I'm not sure if there's any advantages in having this but thought i'd ask. I've got the following code: Code: [Select] <?php header('Content-type: text/xml'); print '<?xml version="1.0"?>'; print '<rss version="2.0">'; print '<channel>'; include("phpfunctions.php"); db_connect(); //select all from users table $select="SELECT title, link, description FROM news"; $result = mysql_query($select) or die(mysql_error()); //If nothing is returned display error no records if (mysql_num_rows($result) < 1) { die("No records"); } //loop through the results and write each as a new item while ($row = mysql_fetch_assoc($result)) { $item_title = $row["title"]; $item_link = $row["link"]; $item_desc = $row["description"]; print '<item>'; print '<title>' . $item_title . '</title>'; print '<link>' . $item_link . '</link>'; print '<description>' . $item_desc . '</description>'; print '</item>'; } print '</channel>'; print '</rss>'; ?> This seems to work fine as i get what i expect and i'm assuming i can do the same to output .xml but is there a way to have it in a proper .rss / .xml file so that an aggregator or someone could read this properly. Cheers, Reece Hi All - I wanted to know if there is any existing script to generate an eticket when a user books a ticket through a website. Thanks I am using this code to evaluate whether checkboxes within a group have been selected: function IsChecked($chkname,$value) { if(!empty($_POST[$chkname])) { foreach($_POST[$chkname] as $chkval) { if($chkval == $value) { return true; } } } return false; } Now, I've decided that I want to add a message upon finding NO SELECTED checkbox items, but it is not functioning as desired. if(empty($_POST[$chkname])) { echo("You didn't select any checkboxes."); } How can I get this or something similar to trigger? I searched online and seen some complex c and c# code which I didn't understand much of. But how do I generate an array with all string combinations based on length and from a charset? E.g. charset = {'a', 'b', 'c'} Length = 2. Then it should generate first all 1-char strings: a b c Then all 2-char strings: aa ab ac ba bb bc ca cb cc And then all added to the same array. I think there's some way of doing it with recursion but to me it's like thinking with a 4th dimension my mind can't grasp this logic! |