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
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.
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
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.
So far all I got is this: - <?php
-
include 'config.php';
-
$table="rating";
-
$item1='food';$item2='code';$item3='rating';
-
$link=new mysqli($host,$usr,$pwd,$db) or exit(1);
-
$link->set_charset('utf8');
-
-
$query="SELECT $item1, $item2, $item3 FROM $table";
-
$result=$link->query($query) or die("Error in query ".mysql_error($link));
-
$format="%s: (USDA code %d), $item3 %d</br>";
-
while ($row=mysqli_fetch_array($result)) {
-
printf($format,$row["$item1"],$row["$item2"],$row["$item3"]);
-
}
-
$link->close();
-
?>
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
Further "progress", pretty wonky but I may be onto something.
The CODE: - <?php
-
include 'config.php';
-
$table="rating";
-
$item1='food';$item2='code'; $rating=0;
-
$link=new mysqli($host,$usr,$pwd,$db) or exit(1);
-
$link->set_charset('utf8');
-
$query="SELECT $item1, $item2 FROM $table";
-
$result=$link->query($query) or die("Error in query ".mysql_error($link));
-
$format="%s: (USDA code %d)</br>";
-
while ($row=mysqli_fetch_array($result)) {
-
?>
-
<html>
-
<head>
-
<title>Userate</title>
-
</head>
-
<body>
-
<input type="number" name="rating" min="0" max="20" maxlength="2"/>Rating<br/>
-
</body>
-
</html>
-
<?php
-
$rating=$_POST['rating'];
-
printf($format,$row["$item1"],$row["$item2"]);
-
}
-
$link->close();
-
?>
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
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bruce A. Julseth |
last post by:
My MySQL.user table (user, host, password) looks like the following:
+---------+-----------+---------------------+
| user | host | password |...
|
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...
|
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...
|
by: Priya |
last post by:
I want to disable individual items in a listbox,listview
in C#.NEt
|
by: kranthi |
last post by:
I want to disable individual items in a listbox or listview
| |
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...
|
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...
|
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...
|
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)?...
|
by: sreenathareddy |
last post by:
How can i store dynamically generated form field values into mysql database table using PHP?
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |
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 ...
|
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...
| |