LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2005, 03:37 PM   #1
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Rep: Reputation: 15
php, mysql error


My database is just a single table with no relations:
create database texter;
create table (titel varchar(255),datum date,text longtext)

I'm getting an error on line 44 wich is around here:



// im using mysql_fetch_array(). il precise a bit
while($row = mysql_fetch_array($result))
{
$texter = $row['titel'];
printf("%s, %s<br />", $texter);



Il admit i dont really know how to insert my database into the php code

I would really appreciate if someone could look at my database structure and just fill in whats missing


Thanks!
 
Old 04-25-2005, 04:33 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Well..
Code:
 printf("%s, %s<br />", $texter);
Two %s, one parameter with value. If I remember correctly it won't use the same for both %s.
 
Old 04-25-2005, 05:25 PM   #3
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
Okay thanks! that worked
edit: once i tested to add something and it didnt work, i removed it and nothing works instead....



But how do i get it to spit out the text and not just the title?

// im using mysql_fetch_array(). il precise a bit
while($row = mysql_fetch_array($result))
{
$texter = $row['titel'];
printf("%s, %s<br />", $texter);


it didnt work to add :
$texter - $row['text']
and another %s

then it just skips everything and goes to else wich is "no posts found"

Last edited by Alexander.s; 04-25-2005 at 05:37 PM.
 
Old 04-25-2005, 09:33 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Code:
$query = mysql_query( "select name, title from user where name = $user ")

while ( list ( $name, $title ) = mysql_fetch_row( $query ))
{
  // do whatever with $name and $title for this row
}
The number of items in the list() call must match the number of items in the select.
 
Old 04-26-2005, 10:00 AM   #5
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
Okay i rearranged my database instead made 2 tables and now it works.

now its just design how do i get title first and the text under it?

like:

(Title) Diablo

(Text) ince the beginning of time, the forces of Order and Chaos have been engaged in an eternal struggle to decide the fate of all Creation. That struggle has now come to the Mortal Realm...and neither Man, Demon, nor Angel will be left unscathed...


And it would be nice to get the text more centered or in a box. its pretty hard to read it like that.


thanks!
 
Old 04-26-2005, 04:28 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Well...write HTML code that should be filled and then just fill it. I don't understand where's the problem. Example:
printf("%s <br />%s<br />", $titel, $longtext);
 
Old 04-26-2005, 04:51 PM   #7
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
there is no problem since you showed me where to put the html code, cuse where i put it i just got errors, wich was 1 cm to the right of where you put it

thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php-mysql error jkmartha Linux - Newbie 4 04-29-2005 04:40 AM
Error connecting to MySQL from PHP anindyanuri Linux - Software 18 04-24-2005 09:30 AM
PHP-MySQL Weird Error Fordor Slackware 2 02-24-2005 12:01 PM
mysql - php socket error. ldp Linux - Software 9 10-22-2004 03:40 AM
PHP/MySql Error cmfarley19 Linux - Software 4 05-12-2003 12:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration