11, October 2008

how do i simplify this snippet? - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: how do i simplify this snippet?
« previous next »
Pages: [1] Print

Author Topic: how do i simplify this snippet?  (Read 777 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« on: Feb 03, 2006, 01:25:26 AM »

what im trying to do is make the code easier to work with by stopping repition of certain lines of code. i have gotten rid of the extra ones but now when say you are user level 5 it only shows those links when it shold show all of them :

Code:
<?php
$new mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
$new mysql_num_rows($new); 
echo("<b><div style=\"font-size: 8pt\">Control Panel</b><br>");
 if ($logged[username] && $logged[level] == 5) {echo("
-<a href=\"?open=12\">User Manager</a><br>
-<a href=\"?open=22\">Page Editor</a><br>
-<a href=\"?open=11\">News Manager</a><br>
-<a href=\"?open=15\">Link Manager</a><br>"
);
}elseif ($logged[username] && $logged[level] >= 2) {echo("
-<a href=\"?open=10\">Submit Link</a><br>
-<a href=\"?open=14\">Modify Link</a><br>"
);
}elseif ($logged[username] && $logged[level] >= 1) {echo("
-<a href=\"?open=7\">Edit Profile</a><br>
-<a href=\"?open=8\">Change Password</a><br>
-<a href=\"?open=9&page=inbox\">Private Messages ($new new)</a><br>
-<a href=\"?open=20\">Logout</a></div>"
);
}else{ echo "<div align=\"center\" style=\"font-size: 8pt\">"; include('login.php'); echo "</div>";}?>

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #1 on: Feb 03, 2006, 01:50:01 PM »

Try this ...

Code:
<?php

$new 
mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'");
$new mysql_num_rows($new);

echo(
"<b><div style=\"font-size: 8pt\">Control Panel</b><br>");

if (
$logged[username] && $logged[level] == 5
{
echo("
-<a href=\"?open=12\">User Manager</a><br>
-<a href=\"?open=22\">Page Editor</a><br>
-<a href=\"?open=11\">News Manager</a><br>
-<a href=\"?open=15\">Link Manager</a><br>"
);
}

if (
$logged[username] && ($logged[level] >= || $logged[level] >= 5)) 
{
echo("
-<a href=\"?open=10\">Submit Link</a><br>
-<a href=\"?open=14\">Modify Link</a><br>"
);
}

if (
$logged[username] && ($logged[level] >= || $logged[level] >= 5))  
{
echo("
-<a href=\"?open=7\">Edit Profile</a><br>
-<a href=\"?open=8\">Change Password</a><br>
-<a href=\"?open=9&page=inbox\">Private Messages ($new new)</a><br>
-<a href=\"?open=20\">Logout</a></div>"
);
}

if (!
$logged[username])

echo "<div align=\"center\" style=\"font-size: 8pt\">"
include('login.php'); 
echo "</div>";
}

?>



Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #2 on: Feb 03, 2006, 07:33:07 PM »

yeah it seems to work pretty nicely now, here is what ive got:

Code:
<?php
$new mysql_query("select * from pmessages where unread = 'unread' and touser = '$logged[username]'"); 
$new mysql_num_rows($new); 

if ($logged[username] && $logged[level] == 5) {$rank "Admin";} 
elseif ($logged[username] && $logged[level] == 2) {$rank "Customer";} 
else {$rank "User";}


if ($logged >= 1) {echo("<b><div style=\"font-size: 8pt\">$rank Control Panel</b><br>");

 if ($logged[username] && $logged[level] == 5) {echo("
-<a href=\"?open=12\">User Manager</a><br>
-<a href=\"?open=22\">Page Editor</a><br>
-<a href=\"?open=11\">News Manager</a><br>
-<a href=\"?open=15\">Link Manager</a><br>"
);}

if ($logged[username] && ($logged[level] >= || $logged[level] >= 5))  {echo("
-<a href=\"?open=10\">Submit Link</a><br>
-<a href=\"?open=14\">Modify Link</a><br>"
);}
if (
$logged[username] && ($logged[level] >= || $logged[level] >= 5))  {

echo("-<a href=\"?open=7\">Edit Profile</a><br>
  -<a href=\"?open=8\">Change Password</a><br>
  -<a href=\"?open=9&page=inbox\">Private Messages ($new new)</a><br>
  -<a href=\"?open=20\">Logout</a></div>"
);}
}else{ echo "<div align=\"center\" style=\"font-size: 8pt\">"; include('login.php'); echo "</div>";}?>

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #3 on: Feb 04, 2006, 05:22:21 AM »

A small tip.

When you are about to print html, you can use something like

echo '<a href="fdfdfdf">';

This way you wont have to put the \" brackets.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #4 on: Feb 04, 2006, 06:29:39 AM »

or...

echo "<a href='fdfdfdf'>";

either one of these is much easier than using \" all the time.


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #5 on: Feb 05, 2006, 04:35:01 AM »

ya ihave tried both of those methods they all work the same way right?

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #6 on: Feb 05, 2006, 06:14:03 AM »

Basically, but at least you don't have to use the backslash (\)...


Last blog : Site of the Month - August 2007
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #7 on: Feb 06, 2006, 12:07:33 AM »

i am still wondering how to let users have more then 1 link ... as-is now i have to manually change their level to 2 and url ID to whatever it is their link will be, after they have paid.. this is slow but getting faster process anyway.. i cant figure how how i will add more then 1 value to the row "urlid" for each user if necessary

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #8 on: Feb 06, 2006, 12:12:01 AM »

If I understand right what you say, you should have different tables for the users and for the sites.

Each site row will have a userID field. Then you will have to use the INNER JOIN statement to retrieve the data.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #9 on: Feb 06, 2006, 07:27:29 AM »

yes the links themselves, and user date (like password) are different tables..so i should get rid of current row on user table "urlid" and add new one to links table as "userid"? this will screw up the current way i have it set up lol

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #10 on: Feb 06, 2006, 10:00:05 AM »

But it is the correct way. While you will be able to have more urls per user. Now you can have more users per url which is ofcourse wrong.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #11 on: Feb 06, 2006, 07:01:28 PM »

ok users table has row : urlid. i delete that right, then create new row on links "urlid"? it already has the row "id" which is auto_inc

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #12 on: Feb 06, 2006, 09:48:50 PM »

Yes you create a new row userId in the url table that points to the user.id field

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #13 on: Feb 06, 2006, 10:07:19 PM »

what do you mean points to user.id field? lol i think u have slightly confused me now haha

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #14 on: Feb 07, 2006, 09:21:03 AM »

I told that meaning the relation of those fields

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1392
Tags : html Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: how do i simplify this snippet?
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct 11, 2008, 05:34:43 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.904
Total Topics: 7.557
Total Members: 4.149
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: mirela

31 Guests, 3 Users online :

13 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.