28, May 2012

how do i simplify this snippet? - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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



« on: Feb 03, 2006, 12: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>";}?>


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


Gimme all your cookies!!!


« Reply #1 on: Feb 03, 2006, 12: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 : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #2 on: Feb 03, 2006, 06: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>";}?>


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



« Reply #3 on: Feb 04, 2006, 04: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #4 on: Feb 04, 2006, 05:29:39 am »

or...

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

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


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #5 on: Feb 05, 2006, 03:35:01 am »

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


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


Gimme all your cookies!!!


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

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


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #7 on: Feb 05, 2006, 11:07:33 pm »

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


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



« Reply #8 on: Feb 05, 2006, 11:12:01 pm »

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 or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #9 on: Feb 06, 2006, 06: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


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



« Reply #10 on: Feb 06, 2006, 09: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 or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #11 on: Feb 06, 2006, 06: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


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



« Reply #12 on: Feb 06, 2006, 08: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 or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #13 on: Feb 06, 2006, 09:07:19 pm »

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


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



« Reply #14 on: Feb 07, 2006, 08:21:03 am »

I told that meaning the relation of those fields

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1392
Tags : html Bookmark this thread : Digg Del.icio.us Dzone more....

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?
May 28, 2012, 04:29:25 am





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: 62.815
Total Topics: 11.029
Total Members: 21.451
Tutorials : 58
Resources : 929
Designs : 395
Latest Member: sobbin

111 Guests, 4 Users online :

12 users online today:




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