EasyCFM.COM ColdFusion Forums / PHP to CFML / php to cfm urgent help plz

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: php to cfm urgent help plz

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

specific
12-25-2007 @ 10:25 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

how can i convert this to cfm to display it property:

<?
include_once "main.php";
$q1 = "select story_id from job_story";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_num_rows($r1);

if ($a1 != '0')
{
    mt_srand((double)microtime() * 1000000);
    $number = mt_rand(1, $a1);

    $q2 = "select story from job_story where story_id = \"$number\"";
    $r2 = mysql_query($q2) or die(mysql_error());
    $a2 = mysql_fetch_array($r2);
    $st = $a2[0];
}
?>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

gmilby
12-26-2007 @ 6:58 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 281
Joined: Nov 2007

it doesn't seem that hard to convert, but the var's at the bottom are representing some key code and it's not there.  

a better question might be 'how do i do ______ in coldfusion?'

if you are not sure what you are looking for, then just explain it the best you can.  maybe someone can at least you give you the correct terminology to search on google for it(?).



Success is the ablity to go from one failure to another with no loss of enthusiasm.
-Sir Winston Churchill

megan
12-26-2007 @ 10:45 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Hi - I know very very little of php but I will take a stab at showing you what I see in the code

in php the $ sign indicates a variable like the double ## signs do in coldfusion

so first they are including another php file named "main.php"

then they are setting a variable $q1 to a sql statement
then they are setting a second variable $r1 to the recordset/result returned by the query (if there is an error show the error)
then they are setting another varible $a1 to the number of rows in the record set

then if the number of rows returned ($a1) does not = 0
create another variable $number from a randomly selected row http://us2.php.net/mt_rand

then they are setting a variable $q2 to another sql statement
then do a second query $r2 selecting a story where story_id = the random number
then return the result as an array http://us2.php.net/mysql_fetch_array

then set another variable $st as the first row in the array (php starts at 0)

at least that's what I get out of the code and I do not know php

I'm sure if I am wrong someone will point out my mistake and I'll learn something today ;D

hth ~megan

We have art so that we shall not die of reality ~ Nietzsche

gmilby
12-26-2007 @ 12:52 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 281
Joined: Nov 2007

that seems to be a pretty good 'pseudo-explaintion'

just curious if there wouldn't be a better way to tackle the target task - Smile

@meg - side note - i got a book for x-mas ray camden, pete freitag/coldfusion mx cookbook... mother in law gave it to me - yesterday she told me that she didn't know what i was into, but she finally figured out it wasn't a 'cookbook - with recipes' LOL... now, it's a little dated but a great book.

Success is the ablity to go from one failure to another with no loss of enthusiasm.
-Sir Winston Churchill

specific
12-26-2007 @ 10:52 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

only this block of code remains...

mt_srand((double)microtime() * 1000000);
    $number = mt_rand(1, $a1);

to be convereted else i have done successfully, Thanks and plz guide me in that

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

megan
12-27-2007 @ 12:04 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

those 3 functions can be looked up & studied at the following links

http://us2.php.net/mt_rand

http://us2.php.net/mt_srand

http://us2.php.net/microtime

~megan

We have art so that we shall not die of reality ~ Nietzsche

specific
01-02-2008 @ 12:13 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

sorry folks, tried a lot but i am stucked now..

this is the code,

$q1 = "select story_id from job_story";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_num_rows($r1);

if ($a1 != '0')
{
    mt_srand((double)microtime() * 1000000);
    $number = mt_rand(1, $a1);

    $q2 = "select story from job_story where story_id = \"$number\"";
    $r2 = mysql_query($q2) or die(mysql_error());
    $a2 = mysql_fetch_array($r2);
    $st = $a2[0];
}

plz plz help me in this i searched alot and read the functions list megan you provided me but cannot make it work though

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

This message was edited by specific on 1-2-08 @ 12:16 PM

gmilby
01-02-2008 @ 2:27 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 281
Joined: Nov 2007

as i stated earlier/initially, there are different methodologies for each language.

mysql connects, queries and sets query parameters on the fly as a free standing variable. what i know about cfml it would be setup much differently.  that is why i was asking what you were 'trying to do'.

as i see it - in cf it would be more like:

<cfif var1 NEQ '0'>
generate a rounded random number from [whatever time it is] to 1000000
<cfset var_number = 2ndRand_var(1, and original value of the var1 variable)>

then in cf the variables would be handled more like


<cfif whatever>
<cfquery ds=... name=....>
select story from job_story
where story_id = var_number
</cfquery>
<cfelseif whatever>
<cfquery ds=... name=....>
select story from job_story
where story_id = var_number
</cfquery>
</cfif>
keeping in mind those last few variables are setting up for things that cf does naturally (like holding/managing the returned array), making the connection (via dsn)/etc

to me - this php snippet doesn't make a tremendous amount of sense because it seems to be missing (or mistyped?) the rand var's and how they're handled... there is mt_srand AND mt_rand(1,$a1) (why?) it's hard to know for certain how to approach this - PLUS, to me, the first part of this code snippet appears to be more for inputting or updating data in a database (as it assigns a random number from the internal clock to one million as a random number to be assigned to the story.

maybe it's just me (not being a coldfusion guru), but i think you'd get much further with just saying, i have.... when i try to do.... it does not... it does... and get some real advice - something you can reuse and understand when you have to go back and work on it.

apologies if i've misspoken but i don't see this post as being constructive as it is. jmho.





Success is the ablity to go from one failure to another with no loss of enthusiasm.
-Sir Winston Churchill


Website Designed and Developed by Pablo Varando.