Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   PHP/MySQL (https://novahq.net/forum/showthread.php?t=31197)

Jeff 11-29-2005 05:33 PM

PHP/MySQL
 
Hey everyone, i've started getting into minor php and mysql but i'm having some troubles.

http://www.exit-thirteen.com

I'm using mysql tables to hold all the info for my site... but i want to setup a form so that i can edit what has already been posted. How do i approach this?

My table rows are:

postID (not shown on webpage)
postTITLE <- the message's title
posterNAME <- now used for user input date
postTIME <- database time (not shown on webpage)
postTXT <- the message

Lakie 11-30-2005 03:03 AM

fetch all the mysql data for a given row and array it

$getnews=mysql_fetch_array(mysql_query("SELECT * FROM whereever WHERE id='1'");

that puts the returned data into an array, accessable by

$getnews[fieldname] (postTXT, postTIME etc)

You could just straight away use the array varibales to poulate a HTML form using the HTML value, and if its just you then you could do this, but it would be an idea to stripslashes, nl2br etc etc to do it properly...

I think anyway, p would be more help...

Scott 11-30-2005 03:08 AM

Alot of people have had very good success learning the basic functions of php by downloading my simple squad site.. it was one of the first scripts I ever wrote so it's pretty basic and easy to follow.

Mikes way above will work except there is one ")" missing at the end of the query, it should look like this:

$getnews=mysql_fetch_array(mysql_query("SELECT * FROM whereever WHERE id='1'"));

Scott 11-30-2005 03:08 AM

Probably help if i posted a link to my script:

http://www.phphq.net/scripts/SimpleSquadSite-v1.2.zip

Lakie 11-30-2005 03:26 AM

Its actually your way (well, everything except the missing )), i learnt it of SSS, would have posted a link but didnt know you offered it for download :)

Scott 11-30-2005 03:41 AM

1 Attachment(s)
I wrote a basic script for you and anyone else that wants to learn.. It all starts from there, at least for me. Basic mysql select, display, delete, modify querys. It's not been debugged so there might be a few phrase errors..

I think you already know how to select data to be displayed but for anyone else that is wondering this is how it would be done following the script attached..

If your wondering what a function does look at http://www.php.net, enter the function name in the search box and read a little, it's extremly well documented, also read the user contributed notes as they help ALOT.
PHP Code:

<?
mysql_connect
("host","user","pass");
mysql_select_db("mysqldb");

$query=mysql_query("SELECT * FROM tbl_name ORDER BY postID ASC LIMIT 10");
while(
$result=mysql_fetch_array($query)) {
extract($resultEXTR_SKIP);

Echo
" ".$postTITLE." <br />";
Echo
" ".$posterNAME." <br />";
Echo
" ".$postTXT." <br />";
Echo
" ".date("m/d/y"$postTIME)." <br />";
Echo
" <br /> ";
Echo
" <br /> ";
}
?>

The above will show the latest 10 news posts..

Note, you will have to right click and view source to see the attached document in it's php form correctly..

Jeff 11-30-2005 05:56 AM

Thanks, should help me out.

SilentTrigger 11-30-2005 12:18 PM

Theres also good info on php.net, thats where i lernt it hehe


All times are GMT -5. The time now is 09:51 AM.

Powered by vBulletin®