473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

presenting MySQL generated table to user's browser to rate individual items for creat

5 New Member
Although a novice to the game, i hope to hit the learning curve at full speed.
I figured out how to present a generic Mysql table to user's browser but now need to add an input column allowing the user to score (rate) row items, then create a user-specific table back in mysql.

user gets some auto-incremented id_# (eg, 100) and I want a table eg, "rate_100" with 2 columns, one for item_id and another for its score given by the user_100.

What would be the most hassle-free approach?
Lots of appreciation
May 9 '14 #1
7 1308
Rabbit
12,516 Recognized Expert Moderator MVP
You should not create a table for each user. Instead, just have on rating table and add a field to identify the user that the rating belongs to.
May 9 '14 #2
evid
5 New Member
Thanks Rabbit, that makes obvious sense, but it isn't the main thing that bugs me.
I can send to user's browser something that looks like this:
acerola,raw: (USDA code 9001), rating 0
apple,raw,w/skin: (USDA code 9003), rating 0
apricots,raw: (USDA code 9021), rating 0
apricot, dried: (USDA code 9032), rating 0

but my problem is how do I make the "rating" field available for input ... in other words something like an HTML that has
"<input type="number" name="rating" min="0" max="10" maxlength="2"/><br/>"
beside every item to be rated.
Once I have that I guess it is fairly straightforward to update the Mysql table at the appropriate user_id field.
Is there a way to open up that rating field that the user sees for input?
Thanks for the brain cell loan
Ed
May 9 '14 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Do just that in your PHP code. Output an input element instead of just the value. It would help if you posted the code you're currently using.
May 9 '14 #4
evid
5 New Member
So far all I got is this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'config.php';
  3. $table="rating";
  4. $item1='food';$item2='code';$item3='rating';
  5. $link=new mysqli($host,$usr,$pwd,$db) or exit(1);
  6. $link->set_charset('utf8');
  7.  
  8. $query="SELECT $item1, $item2, $item3 FROM $table"; 
  9. $result=$link->query($query) or die("Error in query ".mysql_error($link));
  10. $format="%s: (USDA code %d),  $item3 %d</br>";
  11. while ($row=mysqli_fetch_array($result)) {
  12. printf($format,$row["$item1"],$row["$item2"],$row["$item3"]);
  13. }
  14. $link->close();
  15. ?>
That produces the output shown above, where "rating" ($item3) is uniformly NULL and redundant to my purpose since it should be user input not my output (only printed it to display the form shown in the browser).
If I understand what you are saying is that I can stick in something like
$rating=$_POST['rating'];
and then make that part of the
while loop?
like
printf($format,$row["$item1"],$row["$item2"],$row["$rating"]);

must think about how to actually make it work, like I said, I am a newbie, still reading PHP&Mysql off my Kindle ...

Anyway, continued gratitude for your expertise
May 9 '14 #5
evid
5 New Member
Further "progress", pretty wonky but I may be onto something.
The CODE:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'config.php';
  3. $table="rating";
  4. $item1='food';$item2='code'; $rating=0;
  5. $link=new mysqli($host,$usr,$pwd,$db) or exit(1);
  6. $link->set_charset('utf8');
  7. $query="SELECT $item1, $item2 FROM $table"; 
  8. $result=$link->query($query) or die("Error in query ".mysql_error($link));
  9. $format="%s: (USDA code %d)</br>";
  10. while ($row=mysqli_fetch_array($result)) {
  11. ?>
  12. <html>
  13. <head>
  14. <title>Userate</title>
  15. </head>
  16. <body>
  17. <input type="number" name="rating" min="0" max="20" maxlength="2"/>Rating<br/>
  18. </body>
  19. </html>
  20. <?php
  21. $rating=$_POST['rating'];
  22. printf($format,$row["$item1"],$row["$item2"]);
  23. }
  24. $link->close();
  25. ?>
Partial Output:
[input box] Rating
acerola,raw: (USDA code 9001)
[input box] Rating
apple,raw,w/skin: (USDA code 9003)
[input box] Rating
apricots,raw: (USDA code 9021)
[input box] Rating
apricot, dried: (USDA code 9032)

I have to stick in submit button after the while loop is done,
also line input with my sql table values,
also make sure that these ratings correspond to the table rows.

If you spot something obviously wrong or have a more elegant approach, further comment(s) much appreciated / ed
May 9 '14 #6
Rabbit
12,516 Recognized Expert Moderator MVP
There are a couple of ways to go about this.

If you want them to edit one row at a time, make each row a form with it's own submit button. You can include the row id as a hidden input element.

If you want to let them edit multiple rows at a time, change the name of each input box to something like rating_rowid so you can parse it on the other side.
May 9 '14 #7
evid
5 New Member
Thanks again, i'll be signing off for now and follow up on your pointers in the morning ... the second paragraph is the one that sounds like what i need
May 9 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1862
by: Bruce A. Julseth | last post by:
My MySQL.user table (user, host, password) looks like the following: +---------+-----------+---------------------+ | user | host | password |...
6
22508
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid...
6
11186
by: Tom | last post by:
Hi Version of MySQL as yet undetermined but this will be running on White Box - Basically whats the maximum table size in GB that MySQL allows? We are developing an application that streams...
0
1506
by: Priya | last post by:
I want to disable individual items in a listbox,listview in C#.NEt
2
9069
by: kranthi | last post by:
I want to disable individual items in a listbox or listview
0
339
by: Larry | last post by:
Although there are font attribute properties for the items in a ListView component, the complier tells me that they are read-only. Is there any way to get access and change the font poperties of...
2
2147
by: Brian Mitchell | last post by:
Is it possible to gray out individual items in the CheckedListBox? I have an option at the top of the list that simply says 'All', and when the user clicks that item I want the rest of the items in...
2
1725
by: josecruz | last post by:
I have created a combo box for my form. This box displays the individual items properly and runs the report on that particular selection. My question is. How do I code so that a selection of display...
5
1769
by: r3bol | last post by:
Hi, sorry to post this, but I've had a really hard time finding how to do it. Q. How can I break up a value in a list to a list of individual items (preferably without importing any modules)?...
1
1835
by: sreenathareddy | last post by:
How can i store dynamically generated form field values into mysql database table using PHP?
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.