nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you post the latest code (complete code) ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) Okay ! Goodnite!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah.. To reuse your code, functions are always good.. And, the function works fine for me..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Lol..I am not a guru :D ! There are people here who knows php much better than I do.

nav33n 472 Purple hazed! Team Colleague Featured Poster

As I have shown you in my example, where I am assigning $row to $array (which is an array), you can do the same !
You can do,

function fetchAssoc($sql) {
$array = array();
while($row = mysql_fetch_assoc($sql)) {
$array[] = $row;
}
return $array;
}

Then iterate through $array.

OmniX commented: php guru to the rescue! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep ! Have a while loop, insert the values to an array and return the array.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. It will work. But it will return only 1 record, that is the first one (in mysql_fetch_assoc).

nav33n 472 Purple hazed! Team Colleague Featured Poster

It doesn't really matter if you are using mysql_fetch_assoc or mysql_fetch_array. The problem with your function is, you don't have mysql_query in it. So, it will not execute the query at all ! :)
You can do it this way.

$query = "select * from table";
$result = fetchAssoc($query);

function fetchAssoc($sql) {
$result = mysql_query($sql);
 return mysql_fetch_assoc($result) or die("Error!!!");
}
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$connection = Connection();
$query = "select * from attend";
$result = executequery($query);
while($row = mysql_fetch_array($result)) {
	print "<pre>";
	print_r($row);
	print "</pre>";
}
print "<br />";
$result2 = executequeryandreturnrows($query);
print "<pre>";
print_r($result2);
print "</pre>";
function Connection() {
	$conn = mysql_connect("localhost","root");
	mysql_select_db("test");
	return $conn;
}
function executequery($query) {
	$result = mysql_query($query);
	return $result;
}
function executequeryandreturnrows($query) {
	$result = mysql_query($query);
	$array = array();
	while($row = mysql_fetch_array($result)) {
		$array[] = $row['name'];
	}
	return $array;
}
?>

In the above example, I have 3 functions. One for connection(which is pretty straightforward), the second returns the resultset and the third returns the array result.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Well, It depends on your function definition. Can you post relevant code so that we can take a look ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

You have something wrong in your query. Echo the query and execute it in phpmyadmin/mysql console. You will see the problem! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't think you wrote this script. Did you ? hmm.. Anyway, use this script.

<?PHP
// $Id: ClassJVMemberDisplay.php,v 1.4 2008/03/31 16:55:59 scottcase Exp $

class JVMEMBERDISPLAY
{
	
function menu()
{
	if (isset($id))
	{
		$q=new DB;
		$query="select * from members where id='$id'";
		$q->query($query);
		$q->next_record();
		if ($q->f("paid")==0)
		{
			//$u="";
			$oto=" <a href=\"member.area.oto.php\">Purchase OTO</a> | ";
			$adboxallow="";
			//$u="";
			$oto="";
		}
		else
		{
			$u=" <a href=\"member.area.paid.php\">Download</a> | ";
			$adboxallow="<a href=\"index.php?page=adbox_module\">AdBox Module</a> |";
			$oto="";
		}
	}




	$main="<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" class=box>
      <tr align=\"center\">

<!-- add extra info here at top -->
     <br>
<br>
This is where JV's banners go
<html><!-- Start Code --><iframe src=\"http://www.365netmarketing.co.uk/adds/banner.php?action=b&t=true&ref=20&w=468&h=60&grp=13\" width=\"468\" height=\"60\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" vspace=\"0\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"true\" background-color=\"transparent\"></iframe><!-- End Code --></html>



     <br>
<br>
<br>
        <td height=\"20\" class=\"style1\"><span class=\"style3\">
        <a href=\"index.php\">Home</a> |
        <a href=\"index.php?page=profile\">Manage Profile</a> | 
        <a href=\"index.php?page=gift_setup\">Manage Gift</a> | 
        $adboxallow
        <a href=\"index.php?page=promote\">Promote</a> |
        <a href=\"index.php?page=jv_invite\">Invite JV Partners</a> |
        <a href=\"index.php?page=get_gifts\">Get Gifts</a> |
        $u 
        <a href=\"index.php?page=stats\">Referal Stats</a> |
        <a href=\"{helpdeskurl}\" target=_blank>Helpdesk</a> |
        <a href=\"index.php?op=logout\">Logout</a></span></td>
        </tr>
    </table>";
	
	$main=str_replace("{sitename}",$sitename,$main);
	$main=str_replace("{helpdeskurl}",get_setting("helpdeskurl","system"),$main);
	$main=str_replace("{webmasteremail}",$webmasteremail,$main);
	$main=str_replace("{dwld}",$u,$main);
	$main=str_replace("{oto}",$oto,$main);
	
	echo $main;
}

function promote($id)
{
	$q=new DB;
	$currentdate=time();
		$startdate=get_setting("start_date","system");
		if ($currentdate<=$startdate)  { $showform = 0; } else { $showform = 1; }
	$cmember="";
	//$cmember=get_template('template_jv_home_htm');
	FFileRead("templates/jv/template.jv.promotion.tools.htm",$cmember);
	$cmember=str_replace("{buzz_email1_subject}",get_setting("buzz_email1_subject","promotion"),$cmember);
	$cmember=str_replace("{buzz_email1}",get_setting("buzz_email1","promotion"),$cmember);
	$cmember=str_replace("{buzz_email2_subject}",get_setting("buzz_email2_subject","promotion"),$cmember);
	$cmember=str_replace("{buzz_email2}",get_setting("buzz_email2","promotion"),$cmember);
	$cmember=str_replace("{promo_email1_subject}",get_setting("promo_email1_subject","promotion"),$cmember);
	$cmember=str_replace("{promo_email1}",get_setting("promo_email1","promotion"),$cmember);
	$cmember=str_replace("{promo_email2_subject}",get_setting("promo_email2_subject","promotion"),$cmember);
	$cmember=str_replace("{promo_email2}",get_setting("promo_email2","promotion"),$cmember);
	$cmember=str_replace("{promo_email3_subject}",get_setting("promo_email3_subject","promotion"),$cmember);
	$cmember=str_replace("{promo_email3}",get_setting("promo_email3","promotion"),$cmember);
	$cmember=str_replace("{promo_email4_subject}",get_setting("promo_email4_subject","promotion"),$cmember);
	$cmember=str_replace("{promo_email4}",get_setting("promo_email4","promotion"),$cmember);
	$cmember=str_replace("{promo_email5_subject}",get_setting("promo_email5_subject","promotion"),$cmember);
	$cmember=str_replace("{promo_email5}",get_setting("promo_email5","promotion"),$cmember);
	
	$cmember=str_replace("{id}",$id,$cmember);
	
$theform = NULL;

$notyet = "<p align=\"center\"><b>&nbsp;</b></p>
<hr>
<p align=\"center\"><span style=\"font-weight: 700; background-color: #FFFF00\">
<font size=\"6\">Promotion Has Not Started Yet.</font></span></p>
<p align=\"center\"><span style=\"font-weight: 700; background-color: #FFFF00\">
<font size=\"6\">You can invite JV Partners Now.</font></span></p>
<hr>
<p align=\"center\">&nbsp;</p>";


if ($showform) 
{
$cmember=str_replace("{sform}",$theform,$cmember);
}
else
{
$cmember=str_replace("{sform}",$notyet,$cmember); …
nav33n 472 Purple hazed! Team Colleague Featured Poster

$main="<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" class=box>
<tr align=\"center\">

<!-- add extra info here at top -->
<br>
<br>
This is where JV's banners go
<html><!-- Start Code --><iframe src="http://www.365netmarketing.co.uk/adds/banner.php?action=b&t=true&ref=20&w=468&h=60&grp=13" width="468" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true" background-color="transparent"></iframe><!-- End Code --></html>

If you open your script in any good editor, you will see the problem yourself.
You have to escape " in this line.

<html><!-- Start Code --><iframe src="http://www.365netmarketing.co.uk/adds/banner.php?action=b&t=true&ref=20&w=468&h=60&grp=13" width="468" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true" background-color="transparent"></iframe><!-- End Code --></html>

nav33n 472 Purple hazed! Team Colleague Featured Poster

:S hmm..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm..Then you should post your question in javascript forum..

nav33n 472 Purple hazed! Team Colleague Featured Poster

I guess the error has something to do with the script browsercheck.php because I don't see anything strange on line 49 of this script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I am doing great! Thanks..

could I set a variable to get the current date, then use explode (I have no knowledge of this function yet, could you give me an example of it?) to extract the month, and then pass that into the SQL query, so it would always be selecting the current month?

You can simply use, $month = date("m"); to get the current month.
Well, If you want to get the stories for each month, then yep, you have to 'talk to the database' 12 times.
You can use a loop and write a query in that loop.

for($i=1;$i<13;$i++) {
$query = "select * from table where month(datecolumn)='$i'";
//do something
}

If you want to select all the records, you can do it that way too. But then, you have to do alot of processing to do.

$query = "select * from table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
 $datefield = $row['datecolumn'];
//say date is stored as 24-06-2008
list($date,$month,$year) = explode("-",$datefield);
if($month == "06") { //or whatever month
//do something
}
}

Well, its upto you to decide which one is better. I would prefer the 1st method though.
P.S. I have shown the working of explode too!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, Your structure is good.. You can use month function to get the month.

select * from table where month(datecolumn)="06"

If you want to narrow your search and get both year and month,

select * from table where year(datecolumn)="2008" and month(datecolumn)="06";

And, date is a keyword. Its better not to use date as a column name. If you use it, you have to refer the column as `date` in your queries. :)
Cheers,
Nav

Edit: If you don't want to separate it in mysql, you can also do it in php. You can use explode function (if you are storing the date in a different format) or date function.
You are absolutely right about getting the latest 5 stories. But a small change though. It should be desc instead of asc.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Are you sure it isn't working ? Well, I have this code and it works. Oh, btw, I removed unwanted ?> and <?php .

//test.php
<!-- add extra info here at top -->
     <br>
<br>
This is where JV's banners go
<html>
<!-- Start Code -->
<iframe src="http://www.365netmarketing.co.uk/adds/banner.php?action=b&t=true&ref=20&w=468&h=60&grp=13" width="468" height="60" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true" background-color="transparent"></iframe>
<!-- End Code -->
</html>

See the attached image for the screenshot !

nav33n 472 Purple hazed! Team Colleague Featured Poster

There is something wrong with this url.

http://www.365netmarketing.co.uk/adds/banner.php?action=b&t=true&ref=20&w=468&h=60&grp=13

It seems like you have a loop which never ends!
And, you can have html in a php file.

<html>
<body>
Test
</body>
</html>

You can call that test.php .. So, I think the problem is with your php script, banner.php .

nav33n 472 Purple hazed! Team Colleague Featured Poster

How can you differentiate users ? I think you need 2 separate queries. One query to get all the user ids and in the while loop, have another query to calculate the time.

$query = "select distinct(userid) from table"; //query to each user's id
$result = mysql_query($query);

while($row  = mysql_fetch_array($result)) {
  $id = $row['userid'];
$total = 0;
 $query2 = "select * from table where userid = '$id'"; //query to get the relevant records of this user
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_array($result2)) {
//display the records as you are doing now
//also calculate the total_time in this loop
$total = $total + $time; 
} //by the end of this loop, you will have $total (total time) for that particular user
echo "total : ".$total;
} //process next user

You can do it this way :)

kvdd commented: Again he did the job, in the topic: "Show a total in a while". Thanks! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

It would be much better if you post your complete code.

nav33n 472 Purple hazed! Team Colleague Featured Poster

This explains many options for submit buttons
http://www.cs.tut.fi/~jkorpela/forms/imagebutton.html

:'( I am lil too late to reply !

nav33n 472 Purple hazed! Team Colleague Featured Poster
<html>
<head>
<script type="text/javascript">
function showmsg() {
	alert("welcome!");
}
</script>
</head>
<body>
<input type="image" src="calendar.jpg" onclick="javascript: showmsg();" />
</body>
</html>

Like this..

nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't think inserting and displaying would cause the problem! But anyway, problem fixed ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Strange! Does it have something to do with file extension ? :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

Convert the time into minutes(or seconds), add them in the loop, display it converting it back to the way you want !

nav33n 472 Purple hazed! Team Colleague Featured Poster

But she says it there are records but no data in it ! :S really strange!

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) you are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

ah! I see.. So, did it fix the problem or are you still facing some kinda problem ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Few questions..
1. Why are you using sessions before authenticating the user ?
2. Why are you having 2 different queries for checking a valid user ?
3. order by user_name ? You don't need that actually !
And mysql_fetch_array's syntax is
mysql_fetch_array(result, result_type);
result_type = MYSQL_ASSOC or MYSQL_NUM.

$_SESSION==1;

== is a comparison operator, you should use = .
Isn't this a complete reduced version of your code ?

<?php
session_start();

include 'config.php'; //contains $hostname,$username,$password

$connect=mysql_connect($hostname, $username, $password); //connect 
mysql_select_db("worldofp_blog1") or die(mysql_error()); //select db

/* sanitize user's input  */
$user = mysql_real_escape_string($_POST['user']); 
$pass = mysql_real_escape_string($_POST['pass']);


$get="SELECT user_name, pass_word from user where user_name='$user' and pass_word='$pass'"; //check if username and password exists
$result=mysql_query($get) or die(mysql_error());
$is_valid = mysql_num_rows ($result);

if($is_valid) { // if a record exist set $_SESSION['authuser1'] = 1
	echo "hello";
	$_SESSION['authuser1']=1; 
} else { //else set $_SESSION['authuser1'] = 0
	echo "no";
	$_SESSION['authuser1']=0;
}
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

No! I don't have such a large file!

Okay! Since I was jobless, I created a file of 40+ mb (and around 8 lac dummy records) and tried to upload it.. (ofcourse, I had to increase upload_max_filesize = 100M and post_max_size = 100M ) to 100mb.

Its working fine.. :) The script is still running,

Showing rows 0 - 29 (~12,8351 total, Query took 0.0006 sec)

and its still inserting the records..

Edit 2:

Showing rows 0 - 29 (~74,7061 total, Query took 0.0007 sec)

and still inserting..
No problem with your script. Now, I am confused. :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

I tested your code with a small csv file and it works. :-/

The only thing (*I think*) that can go wrong is datatype of the columns not matching with the provided values.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Huh! It created rows but didn't insert data ? :S How is that possible ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$time = "37:00";
list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo date("H:i",mktime(0,$endresult,0,0,0,0));
?>

Now ?

R0bb0b commented: Thankyou +1
kvdd commented: He gives me a complete solution, thanks nav33n! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Just curious, how are you joining those 2 tables ? On what condition ?
If there is no condition for join, wouldn't it give the cartesian product of 2 tables ?
That is, first, it will select all the records from artists_details where ethnicity is 'maori'. Then, it will select the records from attendance table where visit_date >= June 1st and visit_date <= June 19th. :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome.. I *hope* by the time you return, you will see it uploaded! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah.. it does.. Try opening a 30 mb file in notepad.. You can take a nap by the time it opens the file.. Umm.. I don't know how to process a large file.. Lets see if someone else has an idea :(

nav33n 472 Purple hazed! Team Colleague Featured Poster

:?: hmmm.. keep printing $data.. Ie., print_r($data); and see if it prints any data for the large file.. also check how many records does it print..

nav33n 472 Purple hazed! Team Colleague Featured Poster

No matter what you have for max_execution_time in php.ini, But if set_time_limit is 0 (in your script), it uses set_time_limit(0) because its executed during the runtime!

nav33n 472 Purple hazed! Team Colleague Featured Poster

I think

foreach ($result as $entry) {

$result is null or doesn't return an array.

nav33n 472 Purple hazed! Team Colleague Featured Poster

max_execution_time = 60 means the script can take a maximum of 60 seconds to execute (and since you are trying to upload a file which is around 30mb, it will take more than umm..(10 mins ?) long time to process!) . So, you can either set it to 0 or use set_time_limit(0) in your script. If you are working on file uploads, then you have to remove the semicolon before upload_tmp_dir.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Put set_time_limit(0); on top of your script.
http://in.php.net/set_time_limit

maydhyam commented: Great Job.....Thanks :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

:$ I am sorry !!! fgetcsv itself returns an array. You can directly use $data[0],$data[1] and so on..

nav33n 472 Purple hazed! Team Colleague Featured Poster

What exactly do you want ? How is the value stored in the database and how do you want to split it ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you do a thing ? Can you print $data and tell us what it prints ? ( And also, print_r($data_array); )
Btw, You can ignore notices by using error_reporting(E_ALL ^ E_NOTICE);

nav33n 472 Purple hazed! Team Colleague Featured Poster

Since the delimiter you are using is ,, you should explode the data on , and not ;. And also, You don't need move_uploaded_file in your script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

As in this example,

val1_1;val1_2;val1_3;val1_4
val2_1;val2_2;;val2_4

Notice that there is no val2_3. But there is a whitespace in the place of val2_3. So, there are fixed number of columns. I would then explode each row and separate the values.

$data_array = explode(";",$data); 
$value1 = $data_array[0];
$value2 = $data_array[1];
$value3 = $data_array[2];
$value4 = $data_array[3];
//since we know the number of columns in csv file, we can do it this way and even if a column is empty, nothing happens.
$query = "Insert into table (col1,col2,col3,col4) values ('$value1','$value2','$value3','$value4')";
...

This is how I do it.. Maybe someone else has a different idea ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Exactly ! You need to specify the column names in your query..

nav33n 472 Purple hazed! Team Colleague Featured Poster

What if $data has an empty column ? For example, instead of
'test1','test2','test3' if it has 'test1','test3' , then your query will definitely fail (because the column count in the table will not match with the values given).
Did you execute the query in query browser ?