PHP/MYSQL Displaying records

This is a discussion on "PHP/MYSQL Displaying records" within the PHP Forum section. This forum, and the thread "PHP/MYSQL Displaying records are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 21st, 2007, 22:54
Junior Member
Join Date: Jun 2007
Location: London
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation PHP/MYSQL Displaying records

Hey guys,

I am pretty new to php/mysql but have just finished makeing a database of trip reports and a php/html form so users can submit there trip reports directly to the mysql databse.

I have read how to output all this information but what i really need to do is output in a specific way:

I need to only display about 120 characters of the the trip report (as most are over 800 characters) but with a link to a new page where the full trip report can be read.

Is there any way of doing this and also is there anyway php can generate a new page for each record that is submitted? as in if records id 406 is just submitted it has its own page of 406.php?

hope that makes sense and hope you can help!!
Reply With Quote

  #2 (permalink)  
Old Jul 22nd, 2007, 00:44
sannbe's Avatar
SuperMember

SuperMember
Join Date: Dec 2006
Location: San Francisco
Age: 57
Posts: 1,567
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP/MYSQL Displaying records

check php.net

Good information and check the forum. There might be someone there with an answer to your question also.
Last Blog Entry: More Sara Blogging (Nov 29th, 2007)
Reply With Quote
  #3 (permalink)  
Old Jul 22nd, 2007, 05:51
Junior Member
Join Date: Jun 2007
Location: London
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Re: PHP/MYSQL Displaying records

well ive looked absoloutly everywhere and feel like im now going round in circles.

I have managed to put together some php that displays the last 5 records from my database (excluding the trip report as its very long) but i need to add a link to the data that gets outputted so that when its clicked it takes u to a new page that displays that record u clicked with all its information (trip report included)

been looking at some file.php?id=234 but tried it and no luck - am i on the right track?? for some reason when i go that route just displays the information already displayed?!?!

if anyone can help would be VERY much appreciated!!
Reply With Quote
  #4 (permalink)  
Old Jul 22nd, 2007, 11:39
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: PHP/MYSQL Displaying records

Yea, that looks good. If you put the requested id in the link (ex. http://www.yoursite.com/file.php?id=234) then you can read it out like this: $_GET['id'] or $_REQUEST['id']; and use that to read the right trip out of the databank and output it.

Here's an example of how you could do it using PHP and mySQL:
PHP: Select all

<?php
$output
="";
if(isset(
$_GET['id'])) { // output the requested trip report
    
$query=mysql_query("SELECT * FROM table_name WHERE id = '".$_GET['id']."'");
    if(
$row=mysql_fetch_object($query)) {
        
$output.="<p>".$row->trip_report."</p>";
    } else {
        
$output.="Requested id not found in the databank.";
    }
} else { 
// read out all the trip reports
    
$query=mysql_query("SELECT * FROM table_name");
    while(
$row=mysql_fetch_object($query)) {
        
$output.="<a href=\"?id=".$row->id."</a>";
    }
}
// output the generated content
echo($output);
?>
Reply With Quote
  #5 (permalink)  
Old Jul 23rd, 2007, 01:22
Junior Member
Join Date: Jun 2007
Location: London
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Re: PHP/MYSQL Displaying records

Thank you c010depunkk we have a genius in our presence!!

All seems to be working nicely (just gotta get rid of some kinks and tweak a little my end)

Thanks again!
Reply With Quote
  #6 (permalink)  
Old Jul 23rd, 2007, 06:03
Junior Member
Join Date: Jun 2007
Location: London
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP/MYSQL Displaying records

Ok getting close!!! heres my code:

Code: Select all
<?php
$connection = mysql_connect("localhost", "*******", "******") or die("Error connecting to database");
mysql_select_db("paramou4_tripreports", $connection);
if(isset($_GET['id'])) { // output the requested trip report
    $result=mysql_query("SELECT * FROM details WHERE id = '".$_GET['id']."'");
} else
$result = mysql_query("SELECT * FROM details ORDER BY id DESC LIMIT 0, 3", $connection) or die("error querying database");
$i = 0;
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo "class='body1'";}?>>
      <td><strong>Player Name:</strong> 
        <?php echo $result_ar['playername']; ?>
      </td>
      <br />
      <td> <strong>Player Location: </strong> 
        <?php echo $result_ar['location']; ?>
      </td>
      <br />
<td> <strong>Rooms Visited: </strong>
        <?php echo $result_ar['rooms']; ?><br />
      </td>
      <td> <strong>Summary: </strong>
        <?php echo $result_ar['summary']; ?><br />
        <?php echo "<a href=\"index.php?id=".$result_ar['id']."More</a>"; ?>
 
 
<br />
<br />
      </td>
 
</tr>
<?php
$i+=1;
}
mysql_close();
?>
All working ok except for the link comes up as some crazy "index.php?id=7More</a><br /><br /> </td></tr><tr class='body2'> <td><strong>Player Name:</strong> Joe new </td> <br /> <td> <strong>Player Location: </strong> essex new </td> <br /><td> <strong>Rooms Visited: </strong> MGM Bellagio bellagiosas<br /> </td> <td> <strong>Summary: </strong> <br /> <a href="

and links all the records and rows after the first record?? It seems to not close the <a href> tag? tried playing about with it but seems something very small im overlooking? help would be much appreciated and sorry for being a pain!
Reply With Quote
  #7 (permalink)  
Old Jul 23rd, 2007, 06:12
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: PHP/MYSQL Displaying records

You forgot to close the quotation marks and the tag on the link. This should work:

PHP: Select all

<?php
$connection 
mysql_connect("localhost""*******""******") or die("Error connecting to database");
mysql_select_db("paramou4_tripreports"$connection);
if(isset(
$_GET['id'])) { // output the requested trip report
    
$result=mysql_query("SELECT * FROM details WHERE id = '".$_GET['id']."'");
} else {
$result mysql_query("SELECT * FROM details ORDER BY id DESC LIMIT 0, 3"$connection) or die("error querying database");
$i 0;
while(
$result_ar mysql_fetch_assoc($result)){
?>
<tr <?php if($i%== 1) { echo "class='body2'"; } else { echo "class='body1'"; } ?>>
      <td><strong>Player Name:</strong> 
        <?php echo $result_ar['playername']; ?>
      </td>
      <br />
      <td> <strong>Player Location: </strong> 
        <?php echo $result_ar['location']; ?>
      </td>
      <br />
<td> <strong>Rooms Visited: </strong>
        <?php echo $result_ar['rooms']; ?><br />
      </td>
      <td> <strong>Summary: </strong>
        <?php echo $result_ar['summary']; ?><br />
        <?php echo "<a href=\"index.php?id=".$result_ar['id']."\">More</a>"?>
 
 
<br />
<br />
      </td>
 
</tr>
<?php
$i
+=1;
}
mysql_close();
?>
Reply With Quote
Reply

Tags
php mysql records

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in displaying records in single row anilreddy76 Databases 0 Sep 18th, 2007 17:53
Displaying MySQL database tables on a page vandiermen PHP Forum 3 Jun 30th, 2007 21:58
Displaying an Image in php via path in MYSQL chimp PHP Forum 1 Jul 5th, 2006 09:43
reversing records benbacardi Classic ASP 2 Sep 4th, 2004 16:59
Random records.. u2orange Databases 6 Mar 8th, 2004 09:31


All times are GMT. The time now is 11:36.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43