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 1315 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 |
+---------+-----------+---------------------+
| root | localhost | |
| root | % | |
| | localhost | 3823a5ee1f831626 |
| | % |...
|
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 cards, dell 2600/4600's with single channel
backplanes (new ones will have dual channel)
All have 2 gig of ram, but I've never seen mysql use more than 300mb
of ram.
|
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 content - The streams are created
by a CMS from a raw file that gets uploaded by a user - These raw files
are stored in the db by the app. In Oracle i'm used to creating mutiple
datafiles that make up a tablespace and so no singe data file ever
|
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 individual items in the
listview item collection; or is there another control I should consider
using?
My work around for the moment is to use a sub item and show the listview
columns but this takes up more space than I would like and isn't quite...
|
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 the box to become disabled.
Thanks!!
|
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 All items on the combo box?
Thank you
Jose
|
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)?
Like...
(string)
to
|
by: sreenathareddy |
last post by:
How can i store dynamically generated form field values into mysql database table using PHP?
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |