Jump to content

[SOLVED] php help


dannybrazil

Recommended Posts

Hello

 

In my DB i have 5 upload col' (upload_1.....upload_5)

 

if a photo was uploaded it will add the path as string if NOT in will stay NULL

 

i want to tell the user "how many photos he uploaded up to now" i wrote this code but it seems NOT to work :

$upload_1=$row['upload_1'];
$upload_2=$row['upload_2'];
$upload_3=$row['upload_3'];
$upload_4=$row['upload_4'];
$upload_5=$row['upload_5'];


if($upload_1=="" && $upload_2=="" && $upload_3=="" && $upload_4=="" && $upload_5=="")
{
$upload='you have uploaded 0 / 5 photos';
}
elseif(!$upload_1=="" && $upload_2=="" && $upload_3=="" && $upload_4=="" && $upload_5=="")
{
$upload='you have uploaded 1 / 5 photos';
}
elseif(!$upload_1=="" && !$upload_2=="" && $upload_3=="" && $upload_4=="" && $upload_5=="")
{
$upload='you have uploaded 2 / 5 photos';
}
elseif(!$upload_1=="" && !$upload_2=="" && !$upload_3=="" && $upload_4=="" && $upload_5=="")
{
$upload='you have uploaded 3 / 5 photos';
}
elseif(!$upload_1=="" && !$upload_2=="" && !$upload_3=="" && !$upload_4=="" && $upload_5=="")
{
$upload='you have uploaded 4 / 5 photos';
}
elseif(!$upload_1=="" && !$upload_2=="" && !$upload_3=="" && !$upload_4=="" && !$upload_5=="")
{
$upload='you have uploaded 5 / 5 photos';
}

 

any help ?

 

Thnaks

Link to comment
https://forums.phpfreaks.com/topic/174196-solved-php-help/
Share on other sites

Well I hate to ask how it isn't working because frankly, that is a horrible way of going about what you are trying to accomplish.

 

I assume this is the code... after you have queried the database...am I correct?

if so..then

 

I would do this...mind you I just wrote this up..without testing.

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

 

I would keep the 5 columns like you have...ALSO I would make sure that those columns are set to NULL by default.  That way when you go to check them you can just check and see if they are NULL instead of if they are empty

 

now the code

$uploads = array();
$uploads[] = $row['upload_1'];
$uploads[] = $row['upload_2'];
$uploads[] = $row['upload_3'];
$uploads[] = $row['upload_4'];
$uploads[] = $row['upload_5'];

$uploadCount = 0;
foreach($uploads as $upload)   if(!is_null($upload)) $uploadCount++;
echo "You have uploaded " . $uploadCount . " / ", count($uploads), " photos";

 

 

again...may or may not work...and may not be the most accurate way ...but it's definitely better than what you are doing now...no offense

 

because..the way you are doing it......let's say for instance...upload_3 had something and nothing else...figure that one out.

Link to comment
https://forums.phpfreaks.com/topic/174196-solved-php-help/#findComment-918304
Share on other sites

Hey guys

 

Thanks a lot for the quick help.

 

First, i was never good at "for" loops , but i will dedicate my day to learn it

 

i used this example :

$upload_count = 0;

for ($i = 1; $i <= 5; $i++)
{
    if (!empty($row['upload_' . $i]))
    {
        $upload_count++;
    }
}

echo 'you have uploaded ' . $upload_count . ' / 5 photos';

and it work fine!! 

 

thnks again

 

code tags

CODE tags

code tags

-glad everything works now

Link to comment
https://forums.phpfreaks.com/topic/174196-solved-php-help/#findComment-918309
Share on other sites

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.