Jump to content

Recommended Posts

Can anyone help translate this to PHP

 

Dim db, rs, sql, x, m, nowtime

$nowtime=Now()

Set  db = Server.CreateObject("ADODB.Connection")
'db.Open "DSN=allaboutweddings"


sql = "SELECT * FROM Categories WHERE FinishDate>Now() order by Categoryname"


Set rs = db.Execute(sql)
rs.MoveFirst
Do While not rs.EOF

x=x+1

rs.MoveNext
Loop

x=x+0.9
col1=x/3
col1 = Round(col1,0)


m=0
rs.MoveFirst
Do While m<col1
tempcatname=rs("Categoryname")

 

so far i have

<?php
mysql_connect('host','username','password');
mysql_select_db('db name');
$sql = "SELECT * FROM 'Categories' WHERE 'FinishDate' > Now() ORDER BY 'Categoryname'";
$rs = mysql_query($sql);
?>

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

I don't really know asp but from a general coding perspective it looks like you're trying to do this (after the part you already have):

 

Do While not rs.EOF

 

x=x+1

 

rs.MoveNext

Loop

 

looks like you're trying to find out how many rows are returned? that would translate to

 

$x = mysql_num_rows($rs);

 

x=x+0.9

col1=x/3

col1 = Round(col1,0)

 

would be

$x = $x + 0.9;
$col1 = round($x / 3);

 

m=0

rs.MoveFirst

Do While m<col1

tempcatname=rs("Categoryname")

 

I'm assuming this isn't the end of the code, and you are incrementing m in that do while somewhere and doing something with tempcatname?  Not really sure how you are using tempcatname but if it's just a simple var being assigned something new on each iteration, it would be:

 

while ($m < $col1) {
   $t = mysql_fetch_assoc($rs);
   $tempcatname = $t['Categoryname'];
   // other code here
}

 

translating all that literally kinda makes me think that there is probably a better way to actually "say" it (kind of like how literally translating something from one language to another sounds funny grammar wise, etc..)  Maybe if you explain what it is you're trying to do, a more "grammatically correct" way can be given.

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606187
Share on other sites

Ok, i don't get why some of that is needed

<?php
<?php
mysql_connect(temp);
mysql_select_db(temp);
$sql = "SELECT * FROM 'Categories' WHERE 'FinishDate' > Now() ORDER BY 'Categoryname'";
$rs = mysql_query($sql);
$rows = mysql_fetch_assoc($rs);

rs.MoveFirst
$x = mysql_num_rows($rs);

$x = $x + 0.9;
$col1 = round($x / 3);


while ($m < $col1) {
   $tempcatname = $rows['Categoryname'];
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname; ?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname;?></a><br>
<?php
rs.MoveNext
m=m+1
}
?>
</td><td valign="top"><p class="paraspaced" style="margin-left:50px">
<?php
m=0
Do While m<col1
tempcatname=rs("Categoryname")
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname?></a><br>
<?php
rs.MoveNext
m=m+1
Loop
?>
</td><td valign="top"><p class="paraspaced" style="margin-left:50px">
<?php
Do While not rs.EOF
tempcatname=rs("Categoryname")
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname;?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname;?></a><br>
<?php
rs.MoveNext
Loop
rs.close
mysql_close();
?>
</p>
</td>
</tr>
</table>


<?php if($_SESSION['SessionCountyPub'] == "")
{
?>
<p class="para"> </p>
<?php
}
?>

 

I can do some of it , but i cant understand alot of it , or why it is needed

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606189
Share on other sites

I was just asking how you know whether something is necessary or not when you said you didn't know what the script was supposed to be doing.  I think that's a valid question, don't you?

 

And anyways, what other part did you need translated? I don't really see any other pieces in there that are different than the earlier pieces that were already translated, that you can't just wash, rinse and repeat, unless I missed something? But more importantly, like I and others have said, we can't really help you all that much unless we know what it is you're trying to do.  Going back to the whole language translation thing.  Go to any language translator and enter in a sentence and translate it to a different language like say, spanish.  Or go to a spanish site, pick a sentence, and try to translate it.  It's not going to come out the way we would "normally" say it in english, and in fact, it might not mean the same thing at all!

 

Again, if you want some real help, you need to tell us what it is your script is supposed to be doing.

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606401
Share on other sites

This line

Do While not rs.EOF

 

I assume it is something like

 

while(rows[''] != )

{

 

}

 

but im not sure,

and all the bits that say

rs.

something

I have improvised a bit, but as i havent seen a fully working version of this page, due to the fact they created a test one for me, i can only guesss what it is doing from the code, which is that when you select your location you get shown a number of links and they have the location in the link, 

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606420
Share on other sites

It looks like it's for looping through the sql results.  With PHP, after you query the database, it returns a result source (assuming it's valid and there are results to return, etc..) and you then have to retrieve the info out of the result source using a number of functions.  I assume that since in ASP you are refering to column names from the result, you'll want to use like mysql_fetch_assoc so a basic PHP query scenario would look like this:

 


$sql = "select column from table";
$rs = mysql_query($sql);
while($info = mysql_fetch_assoc($rs)) {
   $x = $info['column'];
   echo "$x <br />";
}

 

$rs is the result source returned.  The loop iterates while the condition is true.  What the condition does is grabs the first row in the result source and assigns it to $info and moves an internal pointer to the next row in the result source. 

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606425
Share on other sites

Ok, so this is what i have ,

<?php
mysql_connect('db3.awardspace.com','crazyemochild_pv','Natasha');
mysql_select_db('crazyemochild_pv');
$sql = "SELECT * FROM 'Categories' WHERE 'FinishDate' > Now() ORDER BY 'Categoryname'";
$rs = mysql_query($sql);
$rows = mysql_fetch_assoc($rs);
$x = mysql_num_rows($rs);
$x = $x + 0.9;
$col1 = round($x / 3);
$m = 0;
while ($m < $col1) {
   $tempcatname = $rows['Categoryname'];
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname; ?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname;?></a><br>
<?php
$m = $m+1;
}
?>
</td><td valign="top"><p class="paraspaced" style="margin-left:50px">
<?php
$m=0;
while ($m < $col1) {
$tempcatname = $rows["Categoryname"];
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname?></a><br>
<?php
$m=$m+1;
}
?>
</td><td valign="top"><p class="paraspaced" style="margin-left:50px">
<?php
//Do While not rs.EOF
$tempcatname = $rows["Categoryname"];
?>
<a href="showcats.asp?companytype=<?php echo $tempcatname;?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname;?></a><br>
<?php
//rs.MoveNext
//Loop
mysql_close();
?>
</p>
</td>
</tr>
</table>
<?php
}
if(isset($_SESSION['SessionCountyPub']) != "")
{
?>
<p class="para"> </p>
<?php
}
?>

 

The lines that are commented are what i am confused about

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606426
Share on other sites

//Do While not rs.EOF

$tempcatname = $rows["Categoryname"];

?>

<a href="showcats.asp?companytype=<?php echo $tempcatname;?>&county=<?php echo $_SESSION['SessionCountyPub'];?>">:: <?php echo $tempcatname;?></a><br>

<?php

//rs.MoveNext

//Loop

 

Right.  It looks like what I posted before with the mysql_fetch_assoc.  That looks like the loop runs as long as there are still rows to do something with in rs and .MoveNext looks like it moves the internal pointer to the next row in rs, just like mysql_fetch_assoc does.

Link to comment
https://forums.phpfreaks.com/topic/117852-asp-php-help/#findComment-606436
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.