...

View Full Version : query help



cosmicsea
05-30-2010, 05:02 PM
hi i am using this piece of code to display my pages example.com/users/profile.php?id=5


$res=mysql_query('SELECT * FROM users WHERE u_id="'.mysql_real_escape_string($_GET['id']).'"');

and it works fine but i want to add another level "i guess you could call it" and i want to make the links look something like this "doesnt matter" example.com/users/profile.php?id=5&title=whatever

the example.com/users/profile.php?id=5 would be the profile link but i need something like &title=whatever to show other pages created by the user. title= would db info for whatever entry they may add. cann someone help me? thanks.

sorry if you dont understand this im having trouble explaining it.

DJCMBear
05-30-2010, 05:17 PM
Do you have a database table for the pages they have created if so could you post the sql dump so we can see it.

cosmicsea
05-30-2010, 05:22 PM
Do you have a database table for the pages they have created if so could you post the sql dump so we can see it.

no this is just a test on localhost. i just want to be able to add something like &title=whatever

the row would have user_id, post_id, and title_id

i would use the page title=whatever to grab the assosiated user and posts from them already in the db.

DJCMBear
05-30-2010, 05:35 PM
why dont you just use the id as im guessing the profile id matches up with the users id, so why not use that and in the url have
?id=5&section=other_pages

And in php do an if statement like this


if($_GET['section'] == "other_pages")
{
// Show all other pages for this user id
}
else
{
// Do the current code
}

cosmicsea
05-30-2010, 05:48 PM
why dont you just use the id as im guessing the profile id matches up with the users id, so why not use that and in the url have
?id=5&section=other_pages

And in php do an if statement like this


if($_GET['section'] == "other_pages")
{
// Show all other pages for this user id
}
else
{
// Do the current code
}

that is a good idea. i just need to figure out a way to make this work. i will have to mess with this for a bit.

DJCMBear
05-30-2010, 05:57 PM
If you need any more help on the just post your question here.

cosmicsea
05-30-2010, 06:20 PM
If you need any more help on the just post your question here.

i cant seem to figure this out. maybe i will leave this for another time.

cosmicsea
05-30-2010, 06:24 PM
this is the code that is making it example.com/users/profile.php?id=3


<?php

$res=mysql_query('SELECT u_username,u_full_name FROM users WHERE u_id="'.mysql_real_escape_string($_GET['id']).'"');

if(mysql_num_rows($res) != 1)//no user with that username exists
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"This user does not exist\")
document.location.href='index.php'</script>";
}
else
{
$row=mysql_fetch_assoc($res); //pull the users info
}
?>

pretty simple code, but i cant figure out how to make the section part at the end work with it.

the column 'section' is in is "posts".

im trying to make it so a user can create a new page for text content and name it whatever they want. so the name would be something like example.com/users/profile.php?id=3&section=example

"example" would be the name in the 'section' column in the db

so when someone goes to the page example.com/users/profile.php?id=3&section=example they see all of the assosiated content for that page using post ids and user ids.

DJCMBear
05-30-2010, 06:53 PM
So if I understand corrently you want the user to make a page and they can see all their own posts and other information about themselfs?

Or

The user can make a page and put any text on it they want and others can goto it and see that text like lets say i made a page and called it hello world and wrote hello there world, if a user goes to profile.php?id=123&section=hello_world they could then see the text hello there world?

cosmicsea
05-30-2010, 06:56 PM
I am going to try to make what im trying to do more clear. I am going to make a form for "section" and this will be where the user inputs what the page will be named "coolstuff" ie: example.com/users/profile.php?id=3&section=coolstuff and also on the form will be inputs for text, so when the info goes to the db table "posts" it will go in 1 row with user_id, post_id, and the "section name". I am trying to make it so all the posts in this section ie: "coolstuff" show up in this section "coolstuff" when you goto the url example.com/users/profile.php?id=3&section=coolstuff

I hope that sums it up a bit.

cosmicsea
05-30-2010, 07:00 PM
The user can make a page and put any text on it they want and others can goto it and see that text like lets say i made a page and called it hello world and wrote hello there world, if a user goes to profile.php?id=123&section=hello_world they could then see the text hello there world?

exactly

DJCMBear
05-30-2010, 07:00 PM
Sorry if I have this wrong "again" but is it going to be a comment thing so if someone like you said makes a page called coolstuff then someone posts a comment you want it to show up on that page?

or

Do you mean if a user makes two sections called coolstuff then both sections get merged and both pages content gets put onto one page?

cosmicsea
05-30-2010, 07:08 PM
Sorry if I have this wrong "again" but is it going to be a comment thing so if someone like you said makes a page called coolstuff then someone posts a comment you want it to show up on that page?

or

Do you mean if a user makes two sections called coolstuff then both sections get merged and both pages content gets put onto one page?

ok lets say the user wants to make a list of links they like.

if they submit 3 different links in 3 different form submissions then that would be 3 new rows in the db. each link gets sent there in the table 'posts' in the column content. along with the content will be 3 other columns. "user_id, post_id, and section. I want it so that whatever they post in the one particular section "coolstuff" will only show in "coolstuff". does that help?

DJCMBear
05-30-2010, 07:15 PM
So a mysql table looking like this.


| post_id | user_id | title | content |
| 1 | 1 | hello | Hello There |
| 2 | 1 | dude | Yo Dude |
| 3 | 2 | hello | Hello There |


Would look like this in links and page content.

> row 1
>> URL = example.com/users/profile.php?id=1&section=hello
>> CONTENT = Hello There
> row 2
>> URL = example.com/users/profile.php?id=1&section=dude
>> CONTENT = Yo Dude
> row 3
>> URL = example.com/users/profile.php?id=2&section=hello
>> CONTENT = Hello There

cosmicsea
05-30-2010, 07:17 PM
So a mysql table looking like this.


| post_id | user_id | title | content |
| 1 | 1 | hello | Hello There |
| 2 | 1 | dude | Yo Dude |
| 3 | 2 | hello | Hello There |


Would look like this in links and page content.

> row 1
>> URL = example.com/users/profile.php?id=1&section=hello
>> CONTENT = Hello There
> row 2
>> URL = example.com/users/profile.php?id=1&section=dude
>> CONTENT = Yo Dude
> row 3
>> URL = example.com/users/profile.php?id=2&section=hello
>> CONTENT = Hello There

yes that is correct

DJCMBear
05-30-2010, 07:25 PM
why not use something like this

?id=123&page_id=2 to make it less work for you.

cosmicsea
05-30-2010, 07:33 PM
why not use something like this

?id=123&page_id=2 to make it less work for you.

I will give it a try.

DJCMBear
05-30-2010, 07:42 PM
Ok ill do a sample code which you can edit yourself and I will show the mysql table layouts aswell so you can see the back end too.

- layouts.sql (not realy sql text, it's just a simple table layout)


[table>users]
| id | username | password | email |

[table>pages]
| id | u_id | title | content |


- profile.php


<?php
if(isset($_GET['page_id']))
{
$_ID = mysql_real_escape_string($_GET['id']);
$_PID = mysql_real_escape_string($_GET['page_id']);
$sql = mysql_query("SELECT *
FROM pages
WHERE id = '{$_PID}' && u_id = '{$_ID}'");
if(mysql_num_rows($sql))
{
while($row = mysql_fetch_array($sql))
{
// Do you page code here
}
}
else
{
print "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"This page does not exist\");
window.location.href='profile.php?id={$_GET['id']}';
</script>";
}
}
else
{
$_ID = mysql_real_escape_string($_GET['id']);
$sql = mysql_query("SELECT *
FROM users
WHERE u_id = '{$_ID}'");
if(mysql_num_rows($sql))
{
while($row = mysql_fetch_array($sql))
{
// Do you profile code here
}
}
else
{
print "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"This user does not exist\");
window.location.href='index.php';
</script>";
}
}
?>

The code above will allow you to have a url like this:
example.com/users/profile.php?id=1&page_id=2

cosmicsea
05-30-2010, 07:58 PM
Ok ill do a sample code which you can edit yourself and I will show the mysql table layouts aswell so you can see the back end too.

- layouts.sql (not realy sql text, it's just a simple table layout)


[table>users]
| id | username | password | email |

[table>pages]
| id | u_id | title | content |


- profile.php


<?php
if(isset($_GET['page_id']))
{
$_ID = mysql_real_escape_string($_GET['id']);
$_PID = mysql_real_escape_string($_GET['page_id']);
$sql = mysql_query("SELECT *
FROM pages
WHERE id = '{$_PID}' && u_id = '{$_ID}'");
if(mysql_num_rows($sql))
{
while($row = mysql_fetch_array($sql))
{
// Do you page code here
}
}
else
{
print "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"This page does not exist\");
window.location.href='profile.php?id={$_GET['id']}';
</script>";
}
}
else
{
$_ID = mysql_real_escape_string($_GET['id']);
$sql = mysql_query("SELECT *
FROM users
WHERE u_id = '{$_ID}'");
if(mysql_num_rows($sql))
{
while($row = mysql_fetch_array($sql))
{
// Do you profile code here
}
}
else
{
print "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"This user does not exist\");
window.location.href='index.php';
</script>";
}
}
?>

The code above will allow you to have a url like this:
example.com/users/profile.php?id=1&page_id=2
ok thanks, i will work with that for a bit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum