php - 1 to many mysql statment plus showing images and text -



php - 1 to many mysql statment plus showing images and text -

hi have little problem 1 many statment. adding images in mysql database , in folder part perfect. when want display them tricky part. don't know problem in way i've created database or in code. here both:

my 2 tables text , imagess in text table: text_id - primary text_field - unique

in imagess table: id - primary name title path

my code this:

<?php $result = mysql_query("select * text text_id, imagess id (text_id=id , text_field=title) "); while($row = mysql_fetch_assoc($result)){ echo '<br>№'.$row['text_id'].'<br>'; echo''.$row['title'].'<br>' .$row['text_field']; echo'<br><img src="'.$row['path'].'?url='.$row['path'].'/>'; } ?>

my goal larn how display 1 title + text 2-3 images. hope explain me mistakes because book reading there not such thing.

thank in advance.

in 1-to-many relation, have ignore multiples occurences of "1". have bring together imagess table on foreign key. there errors in query, "from text text_id" means create alias on text named text_id.

<?php $currenttextid = -1; $result = mysql_query("select * text, imagess (text.text_id=imagess.text_id) order text.text_id"); while($row = mysql_fetch_assoc($result)){ if($row['text_id']!=$currenttextid){ $currenttextid=$row['text_id'] echo '<br>№'.$row['text_id'].'<br>'; } echo''.$row['title'].'<br>'.$row['text_field']; echo'<br><img src="'.$row['path'].'?url='.$row['path'].'/>'; } ?>

php mysql one-to-many

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -