Jump to content


Photo

Dynamic Links / database


  • Please log in to reply
4 replies to this topic

#1 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 June 2006 - 01:38 PM

I didnt knwo what to put for the title because this is quite a range of things.

Basically im making a html form, that admins can fill in and when they click sumbit, php will create a new html page, save it with all the variables in, and then display the recently added article in the last 5 added.

Now vie got the form to put the information in the databse. Wisewood is hopefully sending me a script so i can learn how to create the html but my questio nis, how can i increment its name.

When it saves i wanted it to be called "report#.html" basically, ill use the autonumber from the table to create the number #.

my question is basically, is this do able? I can use the autonumber to reference the links on the main page?

I was also thinking it could be masked by a one of those dynamic links like "index.php?reportid=2" How exactly do those kinds of links work?

thanks.


#2 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 08 June 2006 - 01:46 PM

You can get the auto increment number after the insert satement:

$sql = "INSERT INTO tablename VALUES ('',value,value,value)";
$result = mysql_query($sql);
$id = mysql_insert_id();

Now to create the filename:

$filename = "report" . $id . ".html";
;

this should create the filename as: report1.html for example.

These links: index.php?reportid=2 work like this:

<a href="index.php?reportid=2">Click Here To Refresh</a>

<?
if ($_GET['reportid'] == 2) {
  $rep_id = $_GET['reportid'];
  echo "Report ID: " . $rep_id;
}
?>

they are used in links, when the page is refreshed the variable "reportid" is send in the header with the "index.php" this can then be taken with $_GET['varname'] or in case of a form $_POST['varname'] (unless you use GET in the form of course)
http://thewebsolutionprovider.com - A Solution For Everything Web!

#3 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 01:46 PM

When you get the script that i've emailed to you, you want to have that done after the database stuff.

Insert the info into your database, then query the database straight away and get the id of the last entry.

then just include that id into the part of the script i sent you that names the file you're creating.

Second part... if you want to use reports.php?id=2 as the page name to load the html documents, you'd be better off not using html at all.

Create reports.php to the layout etc that you want, and select your info from the database as follows

SELECT * FROM reports WHERE report_id = $_GET[id]

Obviously replacing reports with your table name, and report_id with the name of the field that you auto-increment.
wisewood: proven fact, I am both wise, and wooden.

#4 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 June 2006 - 01:57 PM

[!--quoteo(post=381368:date=Jun 8 2006, 02:46 PM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Jun 8 2006, 02:46 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Create reports.php to the layout etc that you want, and select your info from the database as follows

SELECT * FROM reports WHERE report_id = $_GET[id]

Obviously replacing reports with your table name, and report_id with the name of the field that you auto-increment.
[/quote]

Thanks for that, i think ill give that a try first, seems a lot simpler then what i had in mind.


#5 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 02:13 PM

much better & simpler way of doing it. Thats kinda the whole point of having the database there.

Database & one php file size is nothing in comparison to databse, php file AND several hundred html files containing data stored in the database anyway.
wisewood: proven fact, I am both wise, and wooden.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users