Click here to Skip to main content
11,482,402 members (74,289 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML PHP MySQL Forms
I am developing a Website Where I need to register users, for that I develop a simple HTML Form and use PHP to send data in MYSQL Database, its working perfectly.

But now I need display those profiles[stored in MYSQL Database] one after another
e.g.
Photo                 Profile ID : 1
                      Name : MR. Abc XYz
                      Address : fghgf
                      Qualification: gjhgf
 

PHOTO                Profile ID :2
                     Name:  mno  pqo
                     :
                     :
 
PHOTO                Profile ID :3
                     Name:  bbbb hhhh
                     :
                     :
One page will contain 6-7 profile and then next 6-7 to 2nd page and so on.

This is my problem.
I know its not possible to provide Code for this problem in CodeProject, but please some knowledge or some Links will be help full for me.
Please share your valuable knowledge and please help me.
Posted 3-Sep-12 7:28am
Edited 3-Sep-12 22:21pm
v2
Comments
Sourav Sarkar-SS at 3-Sep-12 14:32pm
   
1 down rating 1 up rating.
please don't rate
please answer or comment for any clarification
Mohibur Rashid at 3-Sep-12 20:43pm
   
I wont rate. But I will give you a link.
www.google.com
Mohibur Rashid at 4-Sep-12 4:40am
   
The point is not informing you about google. it was reminding you about searching online. Most people make a common mistake. if you search your problem you will get solution in 99.99% (its not literal) cases. break down your problems into small pieces and then search online. that was my point.
Sourav Sarkar-SS at 4-Sep-12 5:42am
   
you are a Genius, to solve your problem through google.
great man.
why you are wasting your time in codeproject then.
go and join google.
enhzflep at 4-Sep-12 7:32am
   
Now, now - there's no need to make a sunshine of yourself.
Mohibur's tongue-in-cheek suggestion is perfectly valid. It is unfortunate that his point appears too complex and has been lost on you.

The fact that you see an insult as a fit response to his suggestions further underscore the point.

I suggest you read a copy of Dale Carnegie's book. ;)
enhzflep at 3-Sep-12 21:15pm
   
What exactly is your problem? (it's not clear)
Is it: obtaining 6 or 7 records?
Is it determining which 6 or 7 records?
Is it in displaying the data?
Is it in retrieving the data?

Please use google OR the time required to clearly explain your problem!
Sourav Sarkar-SS at 4-Sep-12 2:51am
   
only the looks and display 6-7 records in a page.
enhzflep at 4-Sep-12 3:10am
   
Following the format you've used in your question:


$sql = "select some stuff limit $firstEntryToShow $lastEntryToShow";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result))
{
$photoSrc = $row[0];
$profileId = $row[1];
$name = $row[2];
$address = $row[3];
$qualif = $row[4];

echo '<table>';
echo '<tbody>';
echo "<tr>";
echo "<td><img src='$photoSrc'/></td>";
echo "<td>Profile ID: $profileId<br>Name: $name<br>Address: $address<br>Qualification: $qualif</td>";
echo '</tr>';
echo '</tbody>';
echo '</table>';
}

Obviously, you'll need to (a) use the right sql for your situation (b) alter the code that extracts results from the query-result record-set. It's most unlikely your photo's src would be the first column in the table, for instance.
Sourav Sarkar-SS at 4-Sep-12 3:19am
   
ok great idea. Thanks. But first 7 records in 1st page and next 7 record in 2nd page and , next 7 records in 3rd page and so one. Please help me regarding this.
enhzflep at 4-Sep-12 3:33am
   
I already asked you that! You indicated it wasn't a problem...
Never the less, let's think about it for a sec.. - page0 will display results 0-6, page1 will display results 7-13 et, etc.
$firstEntry = $pageNumber * 7;
$lastEntry = $firstEntry + 7;

You need to look up the SQL keyword LIMIT. You'll also need to pass the desired pageNumber to the page as either a GET or a POST variable - GET would be the more appropriate - it's not a request that creates/changes data. Also, it gives the user a 'hackable' URL - a URL they can predictably hand-enter.
You can see that when you visit page 2 of Quick Answers, for instance.
Notice the &pgnum=2 part?

http://www.codeproject.com/script/Answers/List.aspx?tab=active&pgnum=2
Sourav Sarkar-SS at 4-Sep-12 3:40am
   
URL writing is possible in PHP like in ASP.NET.
in ASP.NET there is a concept called queryString, is there something in PHP like QueryString.
enhzflep at 4-Sep-12 3:50am
   
No idea.
What's it used for? What's it got to do with the original question?

You *want* the url to contain data that tells you which page to display.
Sourav Sarkar-SS at 4-Sep-12 4:01am
   
I am carrying your idea!
http://www.codeproject.com/script/Answers/List.aspx?tab=active&pgnum=2
"?tab=active&pgnum=2" is called QueryString in ASP.NET.
is there is anything in PHP?
enhzflep at 4-Sep-12 4:18am
   
Sure, you can get any variables passed via the URL in the $_GET array.
There is 1 entry for each variable, the value is accessed by using the variable name as an index into the $_GET array.

Using the url for Quick Answers page 2, you'd have two entries in the array. $_GET['tab'] and $_GET['pgnum']

Try this example on your server, using the following url (replace the directory name as appropriate)
http://localhost/enhzflep/getOpts.php?tab=active&pgnum=1
You should get a page that contains the following 2 lines.

TAB = active
PAGE = 1


--------getOpts.php --------
<?php

$tab = $_GET['tab'];
$pageNum = $_GET['pgnum'];


?>

<!doctype html>
<html>
<head>
</head>
<body>
<?php
echo "TAB = ".$tab . "<br>";
echo "PAGE = ".$pageNum . "<br>"
?>
</body>
</html>
Sourav Sarkar-SS at 4-Sep-12 5:46am
   
ok, got it
I need to study a little bit more.
You post your codes in solution part, so that I accept the Solution.
You gave me 100%, to start with.
Thanks.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As per the comments I added earlier, there's a number of things to keep in mind here.

You need to know:
(1) Which 'page' you'd like to display
(2) How many results you'd like to display on each page.

I've chosen to display the information for each user in a single-row html table. The first cell contains an image, while the second cell contains text information.

I've used single quotes - ' wherever the string doesn't need interpreting. I've used double-quotes " whenever the string contains a php variable that should be substitued by it's value. (It's faster to use single quotes, more functional to use double quotes) - You should consider the code that outputs the image as being wrapped in double-quotes. In this case the string contains an interpreted value inside of single quotes. This will equate to single quotes wrapped around some text value.

$sql = "select some stuff limit $firstEntryToShow $lastEntryToShow";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result))
{
    $photoSrc = $row[0];
    $profileId = $row[1];
    $name = $row[2];
    $address = $row[3];
    $qualif = $row[4];
 
    echo '<table>';
    echo '<tbody>';
    echo "<tr>";
    echo "<td><img src='$photoSrc'/></td>";
    echo "<td>Profile ID: $profileId<br>Name: $name<br>Address: $address<br>Qualification: $qualif</td>";
    echo '</tr>';
    echo '</tbody>';
    echo '</table>';
}

You can set the $firstEntryToShow by taking a variable that specifies which page you'd like to view, and multiplying that value with the number of records your'd like to display on each page. You can then calculate $lastEntryToShow by adding $numEntriesPerPage-1 to $firstEntryToShow.

Note: the code below assumes that the url contains a variable named pgnum
E.g: http://www.somehost.com/someFile.php?pgnum=1
$pageNumber = $_GET['pgnum'];
$numEntriesPerPage = 7;
$firstEntryToShow = $pageNumber * $numEntriesPerPage;
$lastEntryToShow = $firstEntryToShow + ($numEntriesPerPage-1);
You can use isset to see if the variable has been given.
e.g:
 if (isset($_GET['pgnum'])) 
    $pageNum = $_GET['pgnum'];
 else
    $pageNum = 0;
  Permalink  
v2
Comments
Sourav Sarkar-SS at 4-Sep-12 7:18am
   
Ok!
Thanks
Don't delete the comments part, its neccessary for me to build my project.
Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100