What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP help please

PHP help please
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. Huh?  PHP help please
I'm kinda new to making my own functions and i'm having some trouble...

I made this function in a php script I included

code:
function query_db($table){
$data = mysql_fetch_array(mysql_query("SELECT * FROM `".$table."` WHERE id=".$_GET['id']));
return $data;
}


and then I wanted to execute it, and typed

code:
query_db("imdb_data_title");


after the including, but that didn't work, later a friend helped a little and we managed to make it work like this:

code:
$data = query_db("imdb_data_title");


If somone knows a better way of doing that please tell me :)

Then another thing that doesn't work yet...

I have another function in the same script

code:
function link_rewrite(){
//Voor op de profielen worden de films veranderd door links
//actor
$actor = str_replace("Paris Death Monkeys (2004)","<a href=\"title.php?id=2\">Paris Death Monkeys (2004)</a>", $actor);
$actor = str_replace("Ameland: The Movie (2003)","<a href=\"title.php?id=1\">Ameland: The Movie (2003)</a>", $actor);
$actor = str_replace("\"Bredero\" (2004)","<a href=\"title.php?id=0\">\"Bredero\" (2004) </a>", $actor);

//writer
$writer = str_replace("Paris Death Monkeys (2004)", "<a href=\"title.php?id=2\">Paris Death Monkeys (2004)</a>", $writer);
$writer = str_replace("Ameland: The Movie (2003)", "<a href=\"title.php?id=1\">Ameland: The Movie (2003)</a>", $writer);
$writer = str_replace("\"Bredero\" (2004)", "<a href=\"title.php?id=2\">\"Bredero\" (2004)</a>", $writer);
}


It's a little longer but they are all str_replaces with other names
then when I wanted to execute the function I typed this

code:
link_rewrite();


But it doesn't work :(

Can someone please help me with this??

TIA...

[Image: 1-0.png]
             
07-03-2005 04:25 PM
Profile PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: PHP help please
for both of them use global variables

e.g for the first one

add
global $data;
at the beginning of the function
and it will store the mysql data retrieved in the var and it will be usable outside of the function (also you then dont need the return line)

for the second one same thing applies, use global $actor; and global $writer;
07-03-2005 04:31 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP help please
brilliant :), it works :D

Still have to change a lot to make it work better, but you helped me BIG :-)

---------------------------------------------------------------------------------------------------

:o srry for the double post

a little question about global. I tried to make $data['cast'] a global but it said unexpected "[", can't I use this way to make a global, or should i just use $data ?

This post was edited on 07-03-2005 at 07:18 PM by Ezra.
[Image: 1-0.png]
             
07-03-2005 04:39 PM
Profile PM Web Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
37 / Male / Flag
Joined: Jul 2003
RE: PHP help please
just use $data as its an array and its all contents will be globally available then
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
07-03-2005 06:02 PM
Profile E-Mail PM Web Find Quote Report
Fourjays
Full Member
***

Avatar
Jaguar E-Type

Posts: 134
Reputation: 6
35 / Male / –
Joined: Jan 2005
RE: PHP help please
If your new to php (like myself), you can find loads of tutorials. I found this one particularly good:

http://www.php-mysql-tutorial.com/

it seems to cover almost all the basics. I used another tutorial before this, but I wish I ahd found this one earlier - it is so much more detailed, as the author has explained what is going on, rather than just saying "do this but dont do that".
[Image: msgsig7yx.jpg]
A new range of internet based services... Coming Soon(ish)! - www.fortheinter.net
07-03-2005 10:36 PM
Profile E-Mail PM Web Find Quote Report
jren207
Senior Member
****

Avatar
JR! - We <3 Fanta

Posts: 870
Reputation: 28
34 / Male / –
Joined: Sep 2003
RE: PHP help please
I was bored and made this little function. It only really works for getting info from one row of a table that you specify the id or whatever from the $_GET['uname'] part. (I was testing it on a users table). You specifiy the table name and the field you want, db_q('tablename', 'fieldname'); when you use the function

i'm sorta newb, blah :P

code:
<?php

// db function
function db_q($table, $field){

// get variable
$get_name = $_GET['uname'];

// db query
$db_query = mysql_query("SELECT * FROM $table WHERE id = $get_name");

// db fetch array
while($query_row = mysql_fetch_array($db_query)){

// query result
$query_result = $query_row[$field];
}

// return result
return $query_result;
}

// using the function

// echo html table part
echo('<table border="1">
<tr>
<td>
');
// run function
$display_result = db_q('users', 'username');
// echo result from function returned
echo('' . $display_result . '');
// echo html table bit
echo('
</td>
<td>
');

// run function with another table field used
$display_result = db_q('users', 'website');

// echo this field's result
echo('' . $display_result . '');

// echo end of html table
echo('
</td>
</tr>
</table>
');
?>

07-04-2005 12:09 AM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP help please
I used it to make a page like IMDB, but just for some films I made with a friend. It's not done yet, but works very well now :)

BTW... I ripped the lay-out from IMDB couple of years ago already so it doesn't look exaclty the same anymore, but it's just made for fun and to learn PHP better :)

http://school.tsdme.nl/IMDB/title.php?id=2

PS. This site is made for the only purpose of fun for me and a couple of friends, not for phising or anything like that...

I made 3 pages, title for the movies, profile for the profiles of the people and mod.inc.php with functions like opening my database, that dynamic query and a link adder, that basicly changes strings to links.

This post was edited on 07-04-2005 at 01:46 PM by Ezra.
[Image: 1-0.png]
             
07-04-2005 01:44 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On