Unix Technical Forum

Viewing records

This is a discussion on Viewing records within the MySQL forums, part of the Database Server Software category; --> Hello friends, I have a mysql database which I am using in conjuction with PHP in hopes of allowing ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:46 AM
Cyron
 
Posts: n/a
Default Viewing records

Hello friends,

I have a mysql database which I am using in conjuction with PHP in
hopes of allowing my website visitors to view the contents of the
database. I invision an html form which contains the various fields
of the database, along with (next) and (prev) buttons that will
progress respectively through the records. I am running in to
difficulties accomplishing this. This is what i have tried:

//PHP code
$sql = "select * from myTable" ;
$result = mysql_query( $sql ) ;
$row = mysql_fetch_row($result) ;
$description = $row[ 0 ] ;

Now, it was my hope tha I could also pass hidden form values (ie.
$result) which could be used on subsequent (next) clicks to execute
$row = mysql_fetch_row( $result ) and therefore obtain the new values
for the next record. This doesn't seem to be working and it feels
very hackish.

What the correct way to accomplish what I'm trying to do?

Thanks,

Mike

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:46 AM
J.O. Aho
 
Posts: n/a
Default Re: Viewing records

Cyron wrote:
> Hello friends,
>
> I have a mysql database which I am using in conjuction with PHP in
> hopes of allowing my website visitors to view the contents of the
> database. I invision an html form which contains the various fields
> of the database, along with (next) and (prev) buttons that will
> progress respectively through the records.


This had fit a lot better at alt.php.sql.

> I am running in to
> difficulties accomplishing this. This is what i have tried:
>
> //PHP code
> $sql = "select * from myTable" ;

No point asking the SQL to fetch all data, we can limit it with LIMIT x,y

> $result = mysql_query( $sql ) ;
> $row = mysql_fetch_row($result) ;
> $description = $row[ 0 ] ;


/* Just a sloppy test to set a value */
$getthisrow=($_POST['row'])?$_POST['row']:0;
$sql = "select * from myTable LIMIT {$getthisrow},1";
$result = mysql_query( $sql );
$row = mysql_fetch_row($result);
$description = $row[ 0 ];

/* If you use anchor */
$nextlink="page.php?row=".($getthisrow+1);
prevlink="page.php?row=".($getthisrow-1);


> Now, it was my hope tha I could also pass hidden form values (ie.
> $result) which could be used on subsequent (next) clicks to execute


That won't work, the resource won't have any meaning next page.


--

//Aho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:46 AM
Captain Paralytic
 
Posts: n/a
Default Re: Viewing records

On 10 May, 05:18, Cyron <mdigit...@yahoo.com> wrote:
> Hello friends,
>
> I have a mysql database which I am using in conjuction with PHP in
> hopes of allowing my website visitors to view the contents of the
> database. I invision an html form which contains the various fields
> of the database, along with (next) and (prev) buttons that will
> progress respectively through the records. I am running in to
> difficulties accomplishing this. This is what i have tried:
>
> //PHP code
> $sql = "select * from myTable" ;
> $result = mysql_query( $sql ) ;
> $row = mysql_fetch_row($result) ;
> $description = $row[ 0 ] ;
>
> Now, it was my hope tha I could also pass hidden form values (ie.
> $result) which could be used on subsequent (next) clicks to execute
> $row = mysql_fetch_row( $result ) and therefore obtain the new values
> for the next record. This doesn't seem to be working and it feels
> very hackish.
>
> What the correct way to accomplish what I'm trying to do?
>
> Thanks,
>
> Mike


Take a look at phpclasses.org, you'll find ready made classes for
handling all of this.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com