|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
HI everyone! I am new to php and mysql. and I have some problems with building and maintaining a php / MySQL categorized menu system. I will try to explain it in detail.
I am trying to built a simple music or picture, (doesnt matter) web site, which will display categories, like "A, B, C..." in alphabetical order, and from the letters, user can go to different categories. Let's say that I am having three tables, one is "category" ->cat_id ->cat_name (I am using here the alpahabet like "A,B,C...") And the second table is for example "song" ->song_id ->song_title ->song_url ->artist_id ->cat_id And the third one is "artist" ->artist_id ->artist_name ->artist_lastname So far this is the mysql table structure that I have. Please, can you correct me, and tell me how code in oder to let the user choose the category, and then according the "category chosen" to display the right content. THank you very much in advance. I hope I will get soon respond. |
|
#2
|
||||
|
||||
|
Why don't you read a PHP tutorial, try to write some code, and come back with problems/questions when you hit a brick wall?
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
Hey dhouston! Thanks for quick reply...
THe matter is that I did actually write a code and all that stuff Hold on and I am gonig to post it right now... THanks, HawkSapsan |
|
#4
|
|||
|
|||
|
I have two pages, one is category.php, the other one is view.php
THe code in category.php is: <? $db = mysql_connect("host", "user", "pass") or die("could not connect"); mysql_select_db("dbase", $db); $result = mysql_query("SELECT * from category", $db); while ($myrow = mysql_fetch_array($result)) { echo "<div align=left><a href=\"view.php?id=".$myrow["cat_id"]."\">".$myrow["cat_name"]."</a><br></div>"; } ?> And the code in view.php is: <? $db = mysql_connect("host", "user", "pass") or die("could not connect"); mysql_select_db("dbase", $db); $result = mysql_query("select s.song_title, s.song_url, s.artist_id, s.cat_id, a.artist_id, a.artist_name, a.artist_lastname, c.cat_id, c.cat_name from songs s, artist a, category c where s.cat_id=$id", $db); while ($myrow = mysql_fetch_array($result)) { echo "<div align=left>".$myrow["artist_name"]."<br>".$myrow["artist_lastname"]."<br>".$myrow["song_title"]."<br>".$myrow["song_url"]."</div>"; } ?> |
|
#5
|
|||
|
|||
|
Is there something wrong in this code... or how do i have to do it in order to have the right results...
CUz when I execute it, it shows mysql_fetch_array error... Please..if you can help me, I would be really greatful...I have been trying to figure out this probably, last 5 days.... THanks!!!! |
|
#6
|
|||
|
|||
|
No offence but if this has taken you 5 days then you are starting too complicated. Try something a bit simpler. Get a feel for how that works and gradually build up your php and general programming skills. If you just want something done for you pay someone to do it don't expect to come to a forum like this and get it for free.
-KM- |
|
#7
|
|||
|
|||
|
And when I Create table "SONG" and add there the "artist_id" and "cat_id", do I have to make them foreign key, or something like that..?
|
|
#8
|
|||
|
|||
|
No offence Mr. Monkey,
But I thing, this is the forum where they help people to develop their coding skills, and solve the problems that they face with the codes, no matter they are begginers or advanced users. One can be a begginner in PHP, but way advanced developer in C++, or some other languages... ![]() I guess you were right, You can not just come to a FORUM like this and try to SELL your scripts here... ![]() But thanks anyway though...Good help.... |
|
#9
|
||||
|
||||
|
Hawk, please try to be a little more specific. You mention that you get a mysql_fetch_array() error but you don't list the error. Also, you've provided two files and both have calls to mysql_fetch_array() in them. Which is breaking? Both? You're always going to get a quicker response if you provide a concise and painfully clear description of the problem, the code that's causing the problem, and the copied/pasted error message you're receiving, including line numbers (which should be clearly marked in the code) where appropriate.
That said, I'm going to take a wild guess that you're getting the error in view.php and that it's caused by a bad query because $id isn't being interpreted correctly. You should always refer to GET variables as $_GET["id"] (for example) in order to avoid problems like this. Try making that change. If it doesn't work, provide exact error messages and the line numbers and files they occur in. |
|
#10
|
|||
|
|||
|
Dhouston, first of all I really appriciate your help..I will get to the point..
The fisrt file which is category.php is displaying everything correct. It is in the second file that i am having problems to display the content of tables which I tried to join (I dont know if I did it right or wrong), and the error message is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ....../view.php on line 16 which is "while ($myrow = mysql_fetch_array($result))" this line. I did put a varaible called $new_id at the top of code, and posted the value of the $id from category.php with $_GET[" "] function. IF you can help me in this please, I would be really greatful to you... Thanks man! Anyway for those replies! I appriciate it! |
|
#11
|
|||
|
|||
|
This has most likely been caused by your sql statement being incorrect. I suggest you echo it to the browser right before you run the query and see where the problem is. If the error isn't obvious post the sql statement here so we can take a look at it.
-KM- |
|
#12
|
||||
|
||||
|
Oops, didn't see the followup. As kode_monkey suggests, you should echo your SQL. Then copy and paste it into mysql to see if it'll run manually. If it won't, then you can correct your query. If it will, then the problem lies elsewhere (maybe in your mysql_select_db() call -- try adding a die statement to that).
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Please Help To Build A categorized Menu System! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|