nightfox
Feb 13 2007, 05:05 AM
I'm working on a script where there is a custom user profile and I was wondering if there was a more efficient way to grab data stored in a database than this method: CODE $sql = "SELECT * FROM users WHERE `access_name` = \"" .$active_user. "\""; $row = mysql_fetch_array(mysql_query($sql)); //Link the two tables together; grab the most common thing that is the *SAME* $user_id = $row['id']; $sql2 = "SELECT * FROM content WHERE `cid` = \"" .$user_id. "\""; $row2 = mysql_fetch_array(mysql_query($sql2)); Then on the pages, I just do a <?php echo $row2['content']; ?> where ever something is supposed to be. Is this an efficient way? Thanks! I'm trying to "rust off" my PHP knowledge since it has been a while... I'm picking up on a project I quit on a while ago. [N]F
Comment/Reply (w/o sign-up)
faulty.lee
Feb 13 2007, 05:17 AM
QUOTE(nightfox @ Feb 13 2007, 01:05 PM)  I'm working on a script where there is a custom user profile and I was wondering if there was a more efficient way to grab data stored in a database than this method: CODE $sql = "SELECT * FROM users WHERE `access_name` = \"" .$active_user. "\""; $row = mysql_fetch_array(mysql_query($sql)); //Link the two tables together; grab the most common thing that is the *SAME* $user_id = $row['id']; $sql2 = "SELECT * FROM content WHERE `cid` = \"" .$user_id. "\""; $row2 = mysql_fetch_array(mysql_query($sql2)); Then on the pages, I just do a <?php echo $row2['content']; ?> where ever something is supposed to be. Is this an efficient way? Thanks! I'm trying to "rust off" my PHP knowledge since it has been a while... I'm picking up on a project I quit on a while ago. [N]F You should consider using INNER JOIN Something like this CODE $sql = "SELECT users.*, content.* FROM users INNER JOIN content ON content.cid = users.id WHERE users.access_name = \"" .$active_user. "\""; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo $row['content']; }
1. I prefer to split the query into multiple lines, easier to read and manage 2. You should be using mysql_query on a separate line, that way, you can do a check on the mysql_fetch_array or use a while loop, to prevent error in case your contents table contain nothing. 3. INNER JOIN only works if you do not need anything else from the users table, other than to get the id to link with the content table. Other wise you'll have to do it the same way as you did before. 4. Try to return only those column that you need, instead of * everything
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : Grab User Data- [PHP + MySQL] Encrypting Data
- To protect the password of your DB, for example. (13)
Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the MySQL
DB. Here we go! ------------------------------------------------------------------------ CODE
$password = "abc"; $new_password = md5($password); echo $new_password; ?> The password "abc"
was codfied using md5() This will be: 900150983cd24fb0d6963f7d28e17f72 CODE $normal_pass =
"abc"; $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($normal_pass) ==
$encripted_pass) echo "Login Sucessful!"; else echo "Incorrect password."; ?> This c...
How To Create/edit/delete Ftp Accounts With Php
- Help me to create one php page to create FTP user accounts in Unix Ser (2)
Thanks /cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> ...
Mini Apache Server W/ Php
- Grab it right now ... (5)
Hi, Those who don't want to go into all the hassle of configuring Apache with PHP -
here's a quick alternative. Grab MiniApache_PHP from http://213.106.116.50/james/ . It's
a much downscaled version of the real Apache server but includes the PHP modules too - very little
headache over installation and you can start hosting your own sites rightaway. Good alternative for
testing your custom php codes too... This is what the site says about the software: QUOTE
MiniApache_PHP is a cut-down version of the open-source Apache web server software for W...
Reading Xml Data
- Within PHP (2)
How To Reset The Server Variable Php_auth_user
- (9)
Hi, i'm developing a web application which obviously requires a log in/log out script that i
just implementing but i dont know why the log out script dont work fine. The problem is related
with the server variable $_SERVER which remains set even when in the log out script i unset it with
the unset() function. Does someone knows how can i reset or clear the server variable $_SERVER ???
Best regards, ...
Letting Users Add Mysql Data With Php
- (1)
I'm curious as to the best methods of letting users submit data to a MySQL database, displaying
that data, and removing any unwanted tags etc. from it. Currently, there's a handful of PHP
functions that I know of to help with this: mysql_real_escape_string() - perhaps the best known
and most commonly used function, it should be used in pretty much any MySQL query. It escapes
characters that have SQL significance. QUOTE(php.net) ...which prepends backslashes to the
following characters: \x00, \n, \r, \, ', " and \x1a I like to think I made a pretty...
Make A Script Run Even If No User Is Online
- (6)
Hey! Is there any way to make a script run, even if no user is online. Because at the moment, my
scripts run, only when a user is online. And another thing: How can i make the following: (this is
just an example) mysql_query"SELECT maxhp FROM users WHERE username = 'allusers'"; How can I
select all users maxhp, in the same query? Thanks //Feelay...
User Authentication Session Handling Problems
- Authorization server variables not staying across pages (14)
This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I
have been lurking around here at the Asta Host forums with regard to login and user authentication
scripts and I have got as far as this: - Starting a session - Registering a session variable -
Using the variable to check if the user is authenticated or not. - Authenticating the user through
MySQL database - Logging of the user, by setting the session variable to un-authenticated I have
been able to achive the following things too that I think is not related to this proble...
Php, Sql Lite: Storing Session's Data?
- how so store session in SQLITE? (1)
normally, in windows, session data is saved in the location as directed by the "session.save_path"
directives. they only show how to store session data in file. is it possible to store it inside the
SQLite? anyone?...
Automated Product Suggestion Script
- Compare user lists and suggest related items based on pattern matching (2)
I recently got an idea for a project and one of the features I wanted the project to have was an
automated suggestion service. If anyone has been to Amazon, it would work much like their
recommended product feature. What I want to do is take several users lists of whatever but for this
example, I'll use web links like from the browser history. I would want to suggest links to a
user based on common links in many other users lists. User A: Amazon, Ebay, Excite, Google, Yahoo,
MySpace, Walmart User B: Amazon, Ebay, Google, Yahoo, You Tube, MySpace, CVS User C: Amazo...
Getting Certain Parts Of A Record
- The character data (17)
Ok I need help on this puzzling problem. At first I thought that this person stored the dates in the
MySQL database like this: August 27, 2007 That kinda freaked me out a little, because string dates
are hard to manipulate. Then I found out that he stored both th string data and numerical date,
which I found a little bit odd, but it was like this: 2007-08-27 I need to build a PHP program to
manipulate the data, but I need to access the year, month and day respectively by themselves. I
think that isolating the first 4 characters for the year, last 2 characters for da...
Sql Injection Prevention (passing Numerical Data Across Pages).
- PHP/mySQL (9)
Even if your building something as simple as a basic news page for your website, if your passing
along url variable strings like (mysite/index.php?page=1), you may be vulnerable to SQL injection
attacks. For cases like these (passing numerical data in url strings), I have a handy dandy little
function to thwart these attempts silly: CODE // For checking if value is a number, if not
return 1. function isNum($val) { if (!is_numeric($val)) { $val = 1; } return ($val); } I
have this function, within my functions.php file, which I use as an include in files w...
Retrieving Data And Displaying In Boxes
- How do I make a grid of boxes? (6)
I have successfully setup a MySQL Database with a few tables in it to store user input! /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> Woohoo! Now the problem is
displaying the data. I want 4 boxes echoing across with 3 rows down so that makes 12 boxes (12 of
the most recent records). I have no clue how to do this because I cannot use the W3Schools example
of echoing into a table. Here is the code I used but it echoes the same information across th...
Backing Up User Forms As Static HTML
- (5)
System: Activity System for use in Universities Users: Faculty members Scenario: User fills out a
list of activites they participated in. Example: A faculty member attended a seminar about Object
Orientated Programming. They record that seminar into their records by filling out a form and
adding that activity into the database and identifying it with a designed term id. Spring terms are
different than fall terms etc etc. We want to create html snapshots of these forms that can be
included by a simple include('oldForm.html') into another form for review. ...
Data Passing - Re An Assignment For School - Please Help :)
- (8)
I'm working on a small assignment due tomorrow and am having some trouble. I have a functioning
form that you input the data on one php page, and then it does a little math and displays the result
on a new page. The assignment is to make this work on ONE page, and to add some error handling.
I'm having trouble with the basics of passing the data that has been input on the form, back to
itself. I am stuck with a few questions but I'll start with one. I have the data passing back
to itself so that when I start the error checking, the fields won't have ...
Send XML Data To PHP Page
- (0)
Hi, i'm trying to send my xml file "xmlDoc" to a php page so I can save it. Does anyone have the
code for this?...
Need An Alternative To $http_post_data For PHP4
- (5)
Hi, my client's host site currently hosts just 4.0. I tried using the
file_get_contents("php://input") and $HTTML_post_data php file to save the XML file from Flash but
when loaded, it returns nothing. I need hlep...
Storing Data Into Xml With A Php Form
- Need Help! (2)
Hi, I just learned how to read an xml file with PHP. The problem now is that I don't know how to
write onto it. I would like to read my news content and be able to add more to it when another story
comes up but I don't know how to write into the xml via PHP. All I know how to do is to edit the
XML file itself manually. Can anyone help me?...
Multilingual Site: Send The User To Page Of Choice
- (6)
If you have one site in diferent laanguages, this simple script can redirect the user to the correct
page acording to his/her language: CODE // Enslish EUA elseif ($HTTP_ACCEPT_LANGUAGE ==
"en-us"){ header("Location: index_eng.html"); } // Inglês UK elseif ($HTTP_ACCEPT_LANGUAGE ==
"en-gb"){ header("Location: ingles_enuk.html"); } // Portuguese if ($HTTP_ACCEPT_LANGUAGE ==
"pt-br"){ header("Location: index_ptbr.html"); } //German elseif ($HTTP_ACCEPT_LANGUAGE ==
"de-de"){ header("Location: index_ger.html"); } // Swedish elseif ($HTTP_ACCEPT...
Reading Data From Sessions
- (2)
Hello everyone! Before I start let me just say that ive read many threads on here about php and
sessions, several tutorials and the php manual but I still cant find a solution to my problem. My
problem is that when i try to read data from a session it just comes up blank, and an if statement
to see if the variable is null returns true. The code im using is for a login script which checks
the input from a user and compares it with the data in a database to log the user in, this works
fine, also reading the data from the session works perfectly on the page which the sess...
Generating A Table Into A File In CSV Format
- and letting user download the file (6)
I'm working on a project, part of which consists of working with large tables of different
kinds. Now, I'm using a page seeking technique which allows you to browse through the records
depending on which page you want to see and how many records you want to see on each page. Now, I
need a link (or a form button) on each page which, when clicked, will throw a file to the user for
download (the download window should popup immediatly) which will give the part of the table,
currently being viewed, in CSV format. One way I can think of to generate the file is manu...
Php/mysql Data Display
- (3)
Okay .. got a bit of a question here, so I'll do some explaining. I was asked to do a site for
an online roleplaying game, specifically, a "blackbook" site. I accepted and began my quest for
knowledge of PHP. I've gotten quite "far" to the point that I can now take a user inputted
search value and query the database with that value, and then display the values in a table. My
MySQL table setup is as below: CODE |Name|Reports|Type1|Type2|Quote|Confirmed| When queried
it displays the following: CODE Violator Name: # Reports: Offense(s): Quote: ...
Possible To Do?
- Reading a remote website's data .. (7)
What I need to know is how to do the following? I'm completely confused, although I sort of
have a general feel of what I need to do, I just have no clue how to do it. I need to be able to
take some data from one page, displayed on their site as an HTML table, and then output certain
pieces of it to my site. I will disclaim here and now that what I intend to do does not violate
any laws, as I'm not stealing a persons content. I am using this to act as an online counter, to
see how long someone is online. I also have emailed the company to ask if what I'm...
Displaying Data From Mysql?
- (2)
how can i display data from mysql with php, just that on one page i want to display only the first
10 things and the next page the next 20 ...etc.. how can i do that?...
Help With Multi Tier Mysql Application Over Net
- receiving data connection from client (6)
hi.. i want to make a connection from my desktop client into mysql database at web server.
currently i think it can be provided by PHP. 1. i'm thinking like this: CLIENT -> PHP + MYSQL
CLIENT {sent file} -> PHP {receive file, open connection to MYSQL, insert data from file} how it
will be done ??? 2. the security do you know how to secure it ? thanks.....
User Ip And City Tracing In Php
- User IP and City Tracing in PHP (3)
Hi, Am in damm need of tracing the Users IP and City hwre they are from with PHP, Any help
please....... Thanks in Advance Arunkumar.H.G...
Looking for proper, grab, user, data
|
See Also,
*SIMILAR VIDEOS*
Searching Video's for proper, grab, user, data
|
advertisement
|
|