/    Sign up×
Community /Pin to ProfileBookmark

Using a function inside a while statement…

Hello all. well i am doing a database query (using e107 db class), which pulls on average 20-30 rows. I want each row to be extracted, then i want to preform a function called fixdos on each row. I am doing this because when i first started writing the program, i saved the date in this format: 2005-02-01 – but now i want to change those into a unix time stamp. So i have created a temporary column called tempdos. the script grabs the dos, uses the mktime(), then it is supposed to put it back into tempdos. It works, but only for the first row it encounters. Is there something in PHP that doesn’t allow this, or is there a fix for it?

Heres my code, Again, I am using e107s db class functions:

<?php
require_once(“../class2.php”);
require_once(HEADERF);

if(IsSet($_POST[‘doit’])){

$sql -> db_Select(“visits_dvl”, “visit_id, dos”, “dos<‘2004-04-07’ ORDER by dos ASC”);
while($row = $sql -> db_Fetch()){
extract($row);

$tmp = explode(“-“, $dos);
$udate = mktime(0,0,0,$tmp[1],$tmp[2],$tmp[0]);
fixdos($visit_id, $udate);

echo $visit_id.” “.$dos.” “.$udate.”<br/>”;
}

}

$dbr = “
<div style=’text-align:center’>
<form method=’POST’ action = ‘”.e_SELF.”‘>
<input type=’hidden’ name=’doit’ value=’Y’>
<table width=’300px’>
<tr>
<td style=’text-align:center’>Preform database repair</td>
</tr>
<tr>
<td style=’text-align:center’><input type=’submit’ value=’execute’></td>
</tr>
</table>
</form>
</div>”;

echo $dbr;

function fixdos($vi, $d){
global $sql;
$sql -> db_Update(“visits_dvl”, “tempdos='”.$d.”‘ WHERE visit_id='”.$vi.”‘”);

}

?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pyroFeb 01.2005 — [i]Originally posted by decibel [/i]

[B]So i have created a temporary column called tempdos.[/B][/QUOTE]
Could you explain the login behind doing it that way? Seem very counter-intuitive to me - I can't see why you'd temporarily update the database, rather then just have PHP hold the value for you (or perhaps use SQL to output the date as desired)...
Copy linkTweet thisAlerts:
@decibelauthorFeb 01.2005 — because i dont want to delete the column dos until i have made sure the changes have been correctly made. once they are, i will delete the column dos, and reanme the column tempdos to dos. then change my script to read the new date format. please ask me anymore questions if you dont understand, i have run into this problem before. thanks pyro. This is a doctors billing application. It has been storing dates like this since april 2004, so i am very cautious as i make these changes.
×

Success!

Help @decibel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...