473,503 Members | 12,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show selected record in different style

4 New Member
If I use this code to get records from mysql

Expand|Select|Wrap|Line Numbers
  1.           <ul>
  2.             <?php
  3. $cquery = mysql_query ("Select * From product Where category_id=$category_id");
  4. while ( $cr = mysql_fetch_array ($cquery)) {
  5. while ( $pr = mysql_fetch_array ($cquery) ) {
  6. ?>
  7.             <li>
  8.  
  9.               <a href="index.php?product=<?php echo $category_id; ?>&product_id=<?php echo $pr['product_id']; ?>"><?php echo $pr['name']; ?></a>
  10.  
  11.  
  12.             </li>
  13.             <?php  } } ?>
  14.           </ul>
Then how can I apply different style to the clicked product, like if below code results:

product 1
product 2
product 3

And then if some one click on product 1, it should be like this:

product 1
product 2
product 3

I have tried with several things but have not succeeded yet. What is the best way to do this?

Thanks.
Jan 4 '12 #1
7 1794
Rabbit
12,516 Recognized Expert Moderator MVP
I would put each product in it's own container, probably a div, and use the on click event to run a javascript function that changes the class. Don't forget to change the class of the previously selected item back.
Jan 4 '12 #2
ScottEdward
4 New Member
Thanks, but isn't there a way for it be done with if comparison,

like if (selected) then <a class="active"> ???
Jan 4 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
It sounds like you're trying to do it using only PHP but that's impossible because the PHP engine has no idea what elements the user clicks on. That has to be handled on the client side using javascript.
Jan 4 '12 #4
ScottEdward
4 New Member
great, and can I have such example with JS?
Jan 4 '12 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Give it a shot and then post what you have. We can work through the errors you run into.
Jan 4 '12 #6
ScottEdward
4 New Member
Thanks but can you provide me some link where such usage of JS is described because I am a beginner to PHP. :(
Jan 4 '12 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Javascript is unrelated to PHP. You'll want to start out with a tutorial on Javascript. You can try the one on the w3schools website.
Jan 4 '12 #8

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

Similar topics

7
11165
by: ChrisR | last post by:
Hi guys My app is a simple Main form with a few Subforms that are not linked, and a few pop forms. Problem is: I have a pop form with a Listbox with a list of records related to the...
2
1716
by: dbuchanan | last post by:
Hello, I want to open a child form based on the record selected in a dataGridView of the parent form. I want the child form to open with a populated child table based on the selected parent...
8
6014
by: mci | last post by:
Hi! How can I print the selected record? I'm using visual basic 6. After I search the record, it display in the form but when I click the print button all the records will print. What I want is...
7
2945
by: KiwiGenie | last post by:
I have a form which lists selected records, there could be anything from 1 record to all records selected. I want to output a report for each record as HTML. I want each file to take its name from a...
2
2389
by: ndeeley | last post by:
Hello, I've not had a lot of luck getting this to work, despite looking around lots of websites, so here goes... I have a main form frmProjectScheduler. It's a tabbed form and the front page is...
1
2585
by: Bob | last post by:
Hello, Using VB 2005.net. I have a bound datagridview and a delete button control (or when the user pressed the 'Delete' key) I can successfully delete the selected record from the table and...
2
2387
by: Dave | last post by:
Access 2003 I have an unbound search form, which shows filtered search records in it’s sub-form. On the unbound search form I wish to place a button, which will close off the search form, and...
7
11048
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an...
2
2134
by: eneyardi | last post by:
How to filter selected record in a report? i have a form name Data Tracking Details where i can view my records one by one using record selector. Now, i want my current record in a form to be...
2
3252
by: David Patz | last post by:
Is it possible for a user to select a record from a datasheet in a subform, double click it, and write that specific record to another table? I have attempted to perform this task using...
0
7296
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,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
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...
1
5026
isladogs
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...
0
4696
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
3186
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
1524
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 ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
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.