Jump to content

php / mysql data listing


ypkumar

Recommended Posts

hello guys,

 

I'm stuck here:

 

I have a table called customer_messages which has a entryid, custid, fromname, message, flag

i have written a script to enter data into this. and another script to count the number of entries in the table.

 

now i want to display entries in the table on to a script what i did was this:

 

flag is by default '0' which mean unread.

 

insertion code:

 

insert into customer_messages (customer_id,customer_fname,customer_message,flag) values('21','mike','hello!','0')

 

fetching number of unread messages

 

 

select count(*) from customer_messages where flag = '0'

 

$q = "select count(*) from customer_messages where flag = '0'";
$w = mysql_query($q);
$r = mysql_fetch_array($w);
$t = $r[0]; 

 

$t now gives me total number of unread messages in the db.

 

now, I want to display these messages on to a page in the following format:

 

-----------------------------------------------------------------------------------------------

|        sender        |    message                                      |  mark as read  |

-----------------------------------------------------------------------------------------------

|  name_from_db  |  message_from_db                          |    check box    |

-----------------------------------------------------------------------------------------------

|  name_from_db  |  message_from_db                          |    check box    |

-----------------------------------------------------------------------------------------------

   

how do I do this?

 

I'm assuming that I have to use a loop here, I put the code in a while loop, but that didnt work out for me.

can I use a for loop here? if yes how do i use it?

 

my brain's froze now so, i cant think atm, can someone help me out please?

 

=================================================================================

 

in short i need the data from database to be listed as listbox control in asp.. is it possible?

Link to comment
https://forums.phpfreaks.com/topic/225413-php-mysql-data-listing/
Share on other sites

hi pikachu (:P)

 

as i mentioned earlier "$t now gives me total number of unread messages in the db."

 

ofcourse it doesnt list all the elements, this is what i thought i must do

 


<table>
     <tr>
          <td>
               sender
          </td>
          <td>
               message
          </td>
          <td>
               mark as read
          </td>
     </tr>
<?php
$q = "select customer_fname, customer_message from customer_messages where flag = '0'";
$w = mysql_query($q);
while($r = mysql_fetch_array($w))
{?>
     <tr>
          <td>
               <?php echo $r['customer_fname'];?>
          </td>
          <td>
               <?php echo $f['customer_message'];?>
          </td>
          <td>
               <input type="checkbox"  name="read" value="1" />
          </td>
     </tr>
}

 

this code retrieves the first entry from the 'db' which has flag set to '0'.

now I need to fetch all the entries .

 

what do i do? i'm thinking of a for loop, but still cant get my head around on how to put it here.

 

Hi!

 

I don't have any problems with fetching the array, I am having problems in presenting the data fetched.

I have solved the problem myself :)

 

 

i've used this mysql_fetch_assoc() instead of mysql_fetch_array()

 

----- now the problem lies in within the next leg of the page.

<table>
     <tr>
          <td>
               sender
          </td>
          <td>
               message
          </td>
          <td>
               mark as read
          </td>
     </tr>
<?php
$q = "select customer_fname, customer_message from customer_messages where flag = '0'";
$w = mysql_query($q);
while($r = mysql_fetch_assoc($w))
{?>
     <tr>
          <td>
               <?php echo $r['customer_fname'];?>
          </td>
          <td>
               <?php echo $f['customer_message'];?>
          </td>
          <td>
               <input type="checkbox"  name="markasread" value="$f['entryid'];" />
          </td>
     </tr>
}

 

thats show.php and that gives me, a list of messages from different users.

 

================================================================

 

 

now i need to select the checkbox and click a button to approve them.

 

in the next page 'mesenger.php'

 

i need to fetch the id's of members whose checkbox i have clicked on previous page.

i can use $_POST['markasread'];

 

but i need to find out which checkboxes i have checked and which i havent checked.

.

how do i check that?

 

amny help would be greatly appreciated

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.