NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page URGENT php help needed.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 07-11-2006, 02:25 AM THREAD STARTER               #1 (permalink)
Account Suspended
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



URGENT php help needed.


So, I have browse.php or /page-browse/ using mod_rewrite. You can view the file here: http://ryan.xenka.com - now. If you click R, it shows all the users that begin with R but it still has go to page 2, now if you go to page 2 it shows users that don't have a name that begin with R, basically I need help on getting this working so if I do show page R it doesnt say go to page 2 and then show users with another name.

This is my code:

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html;charset=iso-8859-2" />

<link rel="stylesheet" href="images/style.css" type="text/css" />

<title>MusicInterests</title>

</head>

<body>

    <div class="content">

        <div class="header_right">

            <div class="top_info">

                <div class="top_info_right">

                    <p><?php include("logged.php"); ?></p>                    

                </div>        

            </div>

                    

            <div class="bar">

                <ul>

                    <li class="slogan">Navigation:</li>

<?php include("navigation.php"); ?>

                

                </ul>

            </div>

        </div>

            

        <div class="logo">

            <h1><a href="#" title="The best music on the net!">Music <span class="red">Interests</span></a></h1>

            <p>What are you listening too?</p>

        </div>

        

        <div class="search_field">

            <?php include("searchform.php"); ?>

        </div>

        

        <div class="newsletter">

            <p>Subscribe for the Newsletter!</p>

        </div>

        

        <div class="subheader">

            <p><?php include("top.php"); ?></p>

        </div>

        

        <div class="left">

            <div class="left_articles">

                <h2>Browse</h2>

                <p><?php

ob_start
();

include(
"config.php");

if (!
$_GET[user]){

if(!isset(
$_GET['page'])){

$page 1;

} else {

$page $_GET['page'];

}

$max_results "20"// Change to how many member you would like to display per page

$start_var $_GET['start'];

$start_var substr($start_var,0,1);

if(
preg_match("([a-zA-Z])",$start_var))

{

$where_clause "where username like '$start_var"%" "'";

}

else

$where_clause ""

$from = (($page $max_results) - $max_results);

 
$getuser mysql_query("SELECT * FROM users $where_clause ORDER BY username ASC LIMIT $from$max_results");

while (
$user mysql_fetch_array($getuser)){

// gets all the users information.

echo ("<a href=\"/user-$user[username]\">$user[username]</a><br />\n");

// links to a page to view the user's profile.

}

echo 
"Go to page: ";

$total_results mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0);

$total_pages ceil($total_results $max_results);

for(
$i 1$i <= $total_pages$i++){

if((
$page) == $i){

echo 
"$i ";

} else {

echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" title=\"Go to page $i\">$i</a> ";

}

}

} else {

$getuser mysql_query("SELECT * FROM users WHERE username = '$_GET[user]'");

$usernum mysql_num_rows($getuser);

if (
$usernum == 0){
????: NamePros.com http://www.namepros.com/programming/215730-urgent-php-help-needed.html

echo (
"User Not Found");

} else {

mysql_query("update users set views=views+1 where username='$_GET[user]'") or die(mysql_error());

$views mysql_query("select * from users where username='$_GET[user]'") or die(mysql_error());

$resviews = @mysql_fetch_array($views);

$profile mysql_fetch_array($getuser);

echo (
"Username: <i>$profile[username]</i><br />

Location: <i>
$profile[location]</i><br />

Email: <i>
$profile[email]</i><br>

Profile hits: <i>
$resviews[views]</i><br><br />



<b>Music Interests</b><br />

1. 
$profile[artist1] - <i>$profile[song1]</i><br />

2. 
$profile[artist2] - <i>$profile[song2]</i><br />

3. 
$profile[artist3] - <i>$profile[song3]</i><br />

4. 
$profile[artist4] - <i>$profile[song4]</i><br />

5. 
$profile[artist5] - <i>$profile[song5]</i><br />

6. 
$profile[artist6] - <i>$profile[song6]</i><br />
????: NamePros.com http://www.namepros.com/showthread.php?t=215730

7. 
$profile[artist7] - <i>$profile[song7]</i><br />

8. 
$profile[artist8] - <i>$profile[song8]</i><br />

9. 
$profile[artist9] - <i>$profile[song9]</i><br />

10. 
$profile[artist10] - <i>$profile[song10]</i><br />

"
);

// in the above code, we display the user's information.

}

}

?><br /><br />Looking for a specific username?<br /><a href="page-browse">All</a> - 

<a href="browse-A">A</a> - <a href="browse-B">B</a> - <a href="browse-C">C</a> - <a href="browse-D">D</a> - <a href="browse-E">E</a> - <a href="browse-F">F</a> - <a href="browse-G">G</a> - <a href="browse-H">H</a> - <a href="browse-I">I</a> - <a href="browse-J">J</a> - <a href="browse-K">K</a> - <a href="browse-L">L</a> - <a href="browse-M">M</a> - <a href="browse-N">N</a> - <a href="browse-O">O</a> - <a href="browse-P">P</a> - <a href="browse-Q">Q</a> - <a href="browse-R">R</a> - <a href="browse-S">S</a> - <a href="browse-T">T</a> - <a href="browse-U">U</a> - <a href="browse-V">V</a> - <a href="browse-W">W</a> - <a href="browse-X">X</a> - <a href="browse-Y">Y</a> - <a href="browse-Z">Z</a>

</p>

            </div>

        </div>    

        <div class="right">

                        

            <div class="rt"></div>

            <div class="right_articles">

                <p><b>Most viewed</b><br />The most viewed tool allows you too find the 30 most viewed profiles on musicinterests!</p>

            </div>

            <div class="rt"></div>

            <div class="right_articles">

                <p><b>Links</b><br />

                <?php include("links.php"); ?></p>

            </div>

            <div class="rt"></div>

            <div class="right_articles">

                <p><?php include("sponsor.php"); ?></p>

            </div>

        </div>    

        <div class="footer">

            <p><?php include("footer.php"); ?></p>

        </div>

    </div>

</body>

</html>
electricbeat is offline  
Old 07-11-2006, 07:15 AM   #2 (permalink)
NamePros Member
 
CreedFeed's Avatar
Join Date: Apr 2006
Posts: 186
CreedFeed is on a distinguished road
 



Quickly browsing your code, your problem is getting the page numbers. Your query is:

Code:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0);
You're just grabbing the total number of records in your users table here, not the total number of records that start with a selected letter. Try altering your query to the following:

Code:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users $where_clause"),0);
Including the where clause will ensure you're checking specific letters if requested.

Also note, instead of hardcoding each link to each letter, you can use a simple array of letters and a for loop:

Code:
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
echo '<a href="/page-browse">All</a>&nbsp;';
for($i=0; $i < strlen($letters); $i++) {
    echo '<a href="/browse-'.$letters[$i].'">'.$letters[$i].'</a>&nbsp;';
}
CreedFeed is offline  
Old 07-11-2006, 07:22 AM THREAD STARTER               #3 (permalink)
Account Suspended
Join Date: Jul 2006
Posts: 81
electricbeat is an unknown quantity at this point
 



That works, thank you very much CreedFeed, I have almost finished the frontend of my site.
electricbeat is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:15 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger