Database Results on Website

I have a simple question. On my database lets say i have a field for Repeat (int) and on my website form i have assign the values:

0 = no repeat
1 = repeat daily
2 = repeat weekly

so when a user choose no repeat my database displays on the field 0 but i want to displays the results on my website by “no repeat” instead of " 0 ". Can someone advise me?

hello phpbeginner, you can check the value before it dispay result. store user selection option in some varivable.

suppose user select ‘no repeat’ than

$userselection = 0;
if($userselection == 0)
echo ‘no repeat’;
elseif($userselection == 1)
echo ‘repeat daily’;
elseif($userselection == 2)
echo ‘repeat weekly’;

i hope this will helpful for you.
SR

thank you for your advised, but what happens if a have a code like this:

[php]if ($reminder->num_rows>0){
while($row = $reminder->fetch_object()){
echo “

”;
echo “” . $row->title . “”;
echo “” . $row->note . “”;
echo “” . $row->date_time . “”;
echo “” . $row->alarm_type. “”;
echo “” . $row->repeat_event . “”;
echo “Edit”;
echo “Delete”;
echo “”;[/php]
Which it shows the whole database table

I’m assuming I picked the right on if not you can change it:

Switch($row->repeat_event) {
Case 0:
$row->repeat_event = “No Repeat”;
Break;
Case 1:
$row->repeat_event = “Repeat Daily”;
Break;
Case 2:
$row->repeat_event = “Repeat Weekly”;
Break;
}

Thank you Sabin, but it didnt work i guess this problem is much harder than i though

What’s happening with it? I’m trying to do all this on my phone from work :slight_smile: Are you getting any errors? is it displaying something wrong? I’m no expert but I can’t imagine why it wouldn’t work, can you post all of the corresponding code in its most current state as well as any errors or any output you are seeing.

hello phpbeginner,
try below code
[php]

<? if ($reminder->num_rows>0) { while($row = $reminder->fetch_object()) { echo ""; echo "" . $row->title . ""; echo "" . $row->note . ""; echo "" . $row->date_time . ""; echo "" . $row->alarm_type. ""; if($row->repeat_event == 0) echo "No Repeat"; elseif($row->repeat_event == 1) echo "Repeat Daily"; elseif($row->repeat_event == 2) echo "Repeat Weekly"; echo "Edit"; echo "Delete"; echo ""; ?>

[/php]

Note: if $row->repeat_event is an string than add single quote arround 0,1 and 2 like as
if($row->repeat_event == ‘0’), elseif($row->repeat_event == ‘1’), elseif($row->repeat_event == ‘2’)
if it’s integer than no need to add single quote.

SR

Thank you to you both, now it works…!!! we can mark this post as solve

Sponsor our Newsletter | Privacy Policy | Terms of Service