nav33n 472 Purple hazed! Team Colleague Featured Poster

You can give print_r(objectname) to check what values does these variables hold and debug !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great :)

nav33n 472 Purple hazed! Team Colleague Featured Poster
update table set number=number+300 where condition;

You mean like this ?

Edit: Or are you talking about concatenation ?

update table SET number = concat( number, "00" ) WHERE condition; //this will concat 00 to the value in number field for that condition
kevin wood commented: extremely helpful all the time +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

I haven't used PDO classes. But maybe a "return" in the connect function will do the trick ?

public function connect() {
$pdoConnect = new PDO($this->dsn, $this->username, $this->password);
return $this->connection = $pdoConnect;
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Thats because of the first line of your code. The javascript redirection. Everytime you open the page, it will see if the session variable is set. Obviously, it will be empty. So it keeps redirecting :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Your script looks good. But are you sure you have a varchar field in the table called user_password with length greater than 16 characters ? Thats the only thing that I can think of. http://dev.mysql.com/doc/refman/5.0/en/password-hashing.html

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm..That shouldn't reset the session.. But anyway, you can try with an echo statement..
But this is strange.. Are you sure you dont have session_destroy or session_regenerate_id in your script ? hmm..

nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

No :(

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. just curious.. Are you trying sql injection ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Doesn't this work ?

<?php
$merc_list = explode(",",$merc_mailingList);
for($i=0; $i<count($merc_list); $i++) {
 if($i <=200) {
 	//send mail 
 } else {
 	//you can't send any more mails today
 }
}
echo "200 out of ".count($merc_list)." mails have been sent today !";	
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. You mean, you want to assign SOYA, JUN08, 4043.00 , 4060.00 etc in a separate variable ? Well, You have to change how textcontent returns the value. You should rather format it something like this.
array[1] =>
array("contractbuy") = "SOYA",
array("pricesell") = "JUN08",
... and so on..

You need to use multi-dimensional array in textContent..

nav33n 472 Purple hazed! Team Colleague Featured Poster
$dom = new DomDocument();
$value = array();
$dom->loadHTMLFile("http://www.website.com");
$titles = $dom->getElementsByTagName("table");
foreach($titles as $node) {
   $value[] = $node->textContent;
}
//$value[0] will have the first record, $value[1] will have the 2nd record and so on..
nav33n 472 Purple hazed! Team Colleague Featured Poster

Sorry to hear bout malaria ! Get well soon :) And, I don't see any difference between the first example and this one.. Umm.. But if you want the records separately, why don't you add each record to an array and print it as you want it !

nav33n 472 Purple hazed! Team Colleague Featured Poster

What do you mean by separate values ? You mean, its displaying 1 row at a time and you want it to be separated ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Instead of echo, assign the value to a variable and insert it to the table.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can make use of max function to get the maximum value. http://nl3.php.net/max
This would be easy if you store the scores in an array and use max to get the maximum value.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do this. If the counter is 0, then display without a break.

for ($c=0; $c < $num; $c++) {
if($c == 0) {
 echo $data[$c];
} else {
        echo $data[$c] . "<br />\n";

    }
nav33n 472 Purple hazed! Team Colleague Featured Poster

This works perfectly fine for me.

<?php
$list = array("ID,Category,Description");

$file = fopen("./csv/DS20080507.csv","a+", 1000);
foreach ($list as $line)
{
	fputcsv($file,split(',',$line));
}
fclose($file);
$row = 1;
$handle = fopen("./csv/DS20080507.csv", "a+");
for($i=1;$i<10;$i++) {
	fwrite($handle,"test1,\t test2, \t test3 \t\n");
}
fclose($handle);
$handle = fopen("./csv/DS20080507.csv", "r+");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
   
    $row++;
    for ($c=0; $c < $num; $c++) {
        echo $data[$c] . "<br />\n";

    }
}
fclose($handle);
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

I haven't done anything of this kind before. How bout storing the users comments in a table ? The blogger can decide what to publish and what to delete just by the click of a button ? After all, you need a table to store the comments. You can have one more column "publish" with a smallint field in the comments table. If its 1, then publish the comment. If it's 0, then you still haven't decided whether to publish it or not !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome to Daniweb!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome to Daniweb Kathi.. Pukey, sounds sweet! ;) heh..

nav33n 472 Purple hazed! Team Colleague Featured Poster

If only admin's details are stored in admin table, then you don't need to change anything. But if the table is used for all the users, then for relevancy, you can have your table name as users.
Why not make id of contacts table a foreign key ? So, for every row in contacts table, there exist a record in users table. Doing so, when you need to display the details of a particular user, you just need his id.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Print the query (the one which is giving you the error, line 39 or 40) and execute it in phpmyadmin.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi

I would like to put a list of ids in an array
and loop to select data from a table using
"IN" in the where clause.

I am not having any success getting this to work.
Any suggestions?

Note:I am using Mysql database, apache, linux/Windows

<?
//array with list of friends to display
$friend = array('1','2','3','4');

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN '$friend'";
$result = mysqli_query($mysqli, $query);

end quote.

You can't do it this way because $friend is an array. So, when you execute the query, it will be,

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN 'array'";

which is wrong. You can use implode function to join the array.

$friend_implode = implode(",",$friend);

Then use it in your query.

$query = "SELECT first, last, number
      FROM friend
      WHERE id IN (".$friend_implode.")";
nav33n 472 Purple hazed! Team Colleague Featured Poster

Print the query and execute it in mysql console/phpmyadmin. There is something wrong with your query. Please use code tags next time, as it will be easy for us to go through your code.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try this.

//php.class.php
<?php
class page
{
var $title;
var $keywords;
var $content;

function display()
{
$x="<html>\n<head>";
$x.=$this->displaykeywords();
$x.=$this->displaytitle();
$x.="</head>\n<body>";
$x.=$this->content;
$x.='</body>';
$x.='</html>';
return $x;

}

function displaytitle()
{
echo '<title>' . $this->title . "</title>\n";
}

function displaykeywords()
{
echo '<meta name="keywords" content="' . $this->title . '">';
}

function setcontent($data)
{
$this->content = $data;
//echo $data;
}
}
?>

And this is index.php

<?php
include "page.class.php";

$clan911 = new page();

$data = "<p>Clan 911 </p>";

$clan911->title = 'Clan 911';
$clan911->keywords = 'CLAN 911';
$clan911->setcontent($data);

$contents = $clan911->display();
echo $contents;
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

The simplest way to solve that error is to print out the query and execute it phpmyadmin / mysql console. You will know the exact problem. You can also try $result = mysql_query($query) or die (mysql_error()); to get the error message. Also, mysql_fetch_row should be used if you are using numeric index for your array. ie., $row[0], $row[1] and so on. If you want associated names, you should use mysql_fetch_array or mysql_fetch_assoc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Why do you need a switch case ? Why not do it directly ?

if($percent > 0 && $percent < 20) { //show red image
} elseif ($percent > 20 && $percent < 50) {
 //show orange image
} elseif ($percent > 50 && $percent < 100) {
//show green image
} 
//... and so on

Your condition will not work because, $percent can have only 1 value. It can't be 1 as well as 10.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

What images ? You can use it in the 2nd foreach loop itself !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Something like this.

foreach($options_array as $value) { 
 $query = "select count(*) as count from opt1 where ans = '$value'";
 $result = mysql_query($query);
 $row = mysql_fetch_array($result);
 $votecount[$value] = $row['count'];
}
$opsum=array_sum($votecount);
foreach($votecount as $key => $value) {	
	$perc=$value*100;
 	echo 'per of '.$key.' is:'.$perc.'<br>';
 	echo 'Total:'.$opsum.'<br>';
 	$percent=$perc/$opsum;
 	echo 'Percentage of '.$key .' is:'. $percent.'<br>';
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay! Here is an example.

$sql="select * from table";
$result=mysql_query($sql)or die(mysql_error());
$rows=mysql_num_rows($result)or die(mysql_error());
$cost_array = array();
for($i=0; $i<$rows; $i++){
$calld=mysql_result($result, $i, 'calldate');
$dst=mysql_result($result, $i, 'dst');
$duration=mysql_result($result, $i, 'duration');
$todescr=mysql_result($result, $i, 'ToDescr');
$cost=mysql_result($result, $i, 'CallCost');
$cost_array[]=mysql_result($result, $i, 'CallCost');
}
$total = array_sum($cost_array);
echo $total;

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

As I mentioned in another thread, have another variable array in the for loop, say, $cost_array. Assign the same value to it. Then do array_sum($cost_array). That will give you the sum of $cost.

nav33n 472 Purple hazed! Team Colleague Featured Poster

No.. Store count for every option in an array. By the end of the foreach loop, you will have an array with count of votes for each answer. You can then get the sum of votes, iterate through the array to get each vote count to calculate the percentage.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Do array_sum($votecount) after foreach loop.

nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

Did you try

if(empty($_POST['imgfile'])) {
        //nothing posted
 } else {
         //image has been uploaded, proceed with the next step
    }
nav33n 472 Purple hazed! Team Colleague Featured Poster

What does your javascript function do btw ? Can you post it here ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can start from here . For username and password check, you can use a where clause and it works this way. http://w3schools.com/php/php_mysql_where.asp

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) Great !

nav33n 472 Purple hazed! Team Colleague Featured Poster

I believe this is what you are trying to do. Depending upon which button the user clicks, you either let him download the song with an mp3 extension, or, stream the song with ram extension ? If thats right, why not do the processing after he submits the form ? That is,

<?php
define("DIR", "other/");
define("FILENAME", "Name");
define("EXTSTR", "ram");
define("EXTDOW", "mp3");


if(isset($_POST['stream'])) {
	echo "Streaming ".$_POST['parts'].EXTSTR;
} 
if(isset($_POST['download'])) {
	echo "Download ".$_POST['parts'].EXTDOW;
}

echo "<FORM NAME=\"form\" METHOD=\"post\" action=\"test.php\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";

$file = DIR.FILENAME."01.";
echo "<option value=$file>Part 1</option>";

$file = DIR.FILENAME."02.";
echo "<option value=$file>Part 2</option>";

$file = DIR.FILENAME."03.";
echo "<option value=$file>Part 3</option>";

$file = DIR.FILENAME."04.";
echo "<option value=$file>Part 4</option>";

$file = DIR.FILENAME."05.";
echo "<option value=$file>Part 5</option>";

echo "</select>";
echo "&nbsp;<INPUT TYPE=\"submit\" VALUE=\"Stream\" name=\"stream\">";
echo "&nbsp;<INPUT TYPE=\"submit\" VALUE=\"Download\" name=\"download\">";
echo"</FORM>";
?>

I hope this is what you are looking for!

Edit: Oops! I don't know what the javascript function dropdown does. But you can have an onsubmit event at the form tag and do the same.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Possible. Here is an example.

<html>
<body>
<form method="post" name="form">
<input type="submit" name="submit" value="page1" onclick="form.action='page1.php';">
<input type="submit" name="submit" value="page2" onclick="form.action='page2.php';">
</form>
</body>
</html>
nav33n 472 Purple hazed! Team Colleague Featured Poster

No. Put the options in an array. Iterate. eg.

$options_array = array("option1","option2");
$votecount = array();
foreach($options_array as $value) {
  $query = "select count(*) as count where opt1 = '$value'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$votecount[$value] = $row['count'];
}
//by the end of this foreach loop, $votecount will have the the votes for each option. You can get the total by doing array_sum. Then again, iterate foreach $votecount value and find out the percentage.
nav33n 472 Purple hazed! Team Colleague Featured Poster
$query = "select count(*) as count from table where opt1 = 'Option 1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['count'];

Try this.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You know what are the available options for voting.. Right ? Can't you store them in the table ? Counting them wouldn't be difficult.

$query = "select count(*) from table where opt1 =  'A'";

This will give you the number of votes for A.

nav33n 472 Purple hazed! Team Colleague Featured Poster

$_FILES

Shouldn't this be $_FILES :)

dottomm commented: Fantastic!!!! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Since its a voting system, I guess you are having a radio button (or checkboxes). I also assume that you are saving pre-defined values in opt1 field. Count the number of votes for each option. Find the total and calculate the percentage.
votes for option A = 1
votes for option B = 4
votes for option C = 2
votes for option D = 3
Total votes = 10
Percentage of votes for A = 100/10 = 10%
Percentage of votes for B = 400/10 = 40%
... and so on..