Jump to content

Recommended Posts

Hi,

 

i'm just starting with PHP & MySQL so my knowledge is very limited, i just created my first form that saves data to MySQL, now i've created another page that fetches the database and shows the results.  Now i want to have pages created for every entry in the database, like entry 1 is ID1 with data: name adress email or whatever, so in the end entry 1 will have a static page accessible through domain.com?id=1 or something like this.

 

The next step would be to have some kind of admin page to edit the data, that is shown.

 

If someone could help me out, or could give me some advice what i need to look for that would be great.

Thanks for your reply, i checked that link, and tried out the code in that thread, unfortunately i'm receiving this error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /public_html/test.php on line 18

You were right, i forgot to edit the table, it's working now, now i'm wondering how would i create a list like page, where it shows lets say 2 tables values like ID and Name, and automatically creates a link to a new page which shows the rest of the table contents ?

 

I'm using the script like this, to show ID, fname1 and lname1 as a preview.

 

<?php
//At the top would use a $_GET parameter
$id = $_GET['id'];

//make mysql connection, use your connection info
$con = mysql_connect("localhost","test","test");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//select your database
mysql_select_db("test", $con);

//query what you want, insert your table name
$result = mysql_query("SELECT * FROM bookings WHERE id='$id'");

//post loop
while($row = mysql_fetch_array($result))
  {
//use your values
  echo $row['id'] ."<br />";
  echo $row['fname1'] ."<br />";
  echo $row['lname1'] ."<br />";
  }

//close the connection
mysql_close($con);
?> 

 

All rows from the table, that i need on the "full view" page are: ID, fname1,lname1,kontaktper,tele1,erreichbarkeittele,email1,hinflug,ruckflug,personen,flughafen,flugklasse

 

Thank you for your help.

Ok now i got this:

 

<?php

$con = mysql_connect("localhost","test_test","test");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//select your database
mysql_select_db("test", $con);

//dummy post post data
$post_id =  range(1,20);
$title = "Link to a post";
$description = "This is a demonstration of linking to a post all using the same file. Depending if you use by id or a specific value would not matter, you just have to set it to those.";
$comment = "blah blah blah is my comment";                   
//end of dummy post data                    
$id = mysql_real_escape_string($_GET['id']);
$home_url = "http://".filter_var($_SERVER['HTTP_HOST'], FILTER_SANITIZE_STRING);
$about_page = "http://get.blogdns.com/dynaindex/info/";
$url = "http://".filter_var($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);

if (!empty($_SERVER["QUERY_STRING"])){
    $url .= "?".filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
}
if ($url == "$home_url") {
$url = "$url?$id";
}

echo "<a href='$home_url'>Home</a><br />";
echo "<a href='$url'>$url</a><br />";
echo "<a href='$about_page'>Info</a><br />";
echo "<br />";
?>

<form name="input" action="<?php echo $url; ?>" method="get">
ID Number or Post Name:<input size="30"type="text" name="post" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="<?php echo $id; ?>">
<input type="submit" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="Go to Post" />
</form>

<?php
if (isset($_GET['id'])){
echo "<h2>Post Content</h2";
echo "<hr>";

$post_link = "<a href='$url$post_number'>Permalink</a><br />";
echo $post_link;
echo "$id<br />";
echo "<p>".$title."<br />".$description."<br />".$comment."</p><br />";
echo "<hr>";
} elseif ($url == "$about_page"){
echo "<h2>About Page</h2";
echo "My way of displaying different content using a single php script";
} else {
echo "<h2>Main Content</h2<br />";
echo "<hr>";
foreach ($post_id as $post_number) {
echo $post_number;
$post_link = "<a href='$url?id=$post_number'>View post</a>";
echo "<p>$post_link</p><br />";
echo "<hr>";

}
echo "<br />";
highlight_file('backend.php'); 
echo "<br />";
}

echo "<br />";



?> 

 

Now i can't seem to find out how i change the "dummy data" to actual data from my tables, i want exactly what that script does, but on the main page where it shows an overview of the posts, i want it to show the overview and include: id, fname1, lname1

 

and the page that gets opened on link click (e.g id?=1) should then contain this rows from my table: : id, fname1,lname1,kontaktper,tele1,erreichbarkeittele,email1,hinflug,ruckflug,personen,flughafen,flugklasse

 

I made that just to show how $_GET works really.

 

But you would query your database for any results would want, grab the id from each post and make a hyperlink linking to a view page, on the view page would use $_GET['id']; , then from there query mysql for just that one id and all the results in a while loop.

 

Depending on how much time I have today, I may make a simple php starter site along with pagination.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.