Lamez Posted January 31, 2008 Share Posted January 31, 2008 I have a few questions. 1. How do I use php in the middle of JS for example: team[2]="<?php include ("example.php"); ?>"; rec[2]="(19-12)"; 2. How do I call rows form a MySQL table? I remeber the php is like: $_ROW['somthing'] but I do not remember, can anyone refresh my memory -Thanks Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/ Share on other sites More sharing options...
drisate Posted January 31, 2008 Share Posted January 31, 2008 you can insert a php var in a js code but canot insert a js var in a php code. Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454323 Share on other sites More sharing options...
The Little Guy Posted January 31, 2008 Share Posted January 31, 2008 1. Your example will work depending on what is in example.php 2. <?php $sql = mysql_query("SELECT * FROM tblName"); while($row = mysql_fetch_array($sql)){ echo $row['columnName'].'<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454325 Share on other sites More sharing options...
monkeytooth Posted January 31, 2008 Share Posted January 31, 2008 js code.... <?php $var function; ?> .... js code........ $sq_hst = "mysql.server"; $sq_unme = "sql.database.user.name"; $sq_pzwrd = "sql.database.password"; $database = "sql.database.name"; //would suggest keeping this line and the 3 above it in a seperate file and just include said file when you need it.. $dbconn = mysql_connect($sq_hst, $sq_unme, $sq_pzwrd) or die("Error: " . mysql_error()); mysql_select_db($database) or die("Could not select database"); $query="SELECT * FROM table.name.on.database"; $result=mysql_query($query) or die ("Error in query: $query. " . mysql_error()); $result1 = mysql_fetch_array( $result ); echo $result1['row.on.table.name']; mysql_close(); Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454331 Share on other sites More sharing options...
drisate Posted January 31, 2008 Share Posted January 31, 2008 The reason why you canot insert a JS var in a PHP code is because The first thing executed by the server is the PHP so the JS var will appear emty entile the PHP is done. Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454335 Share on other sites More sharing options...
The Little Guy Posted January 31, 2008 Share Posted January 31, 2008 You can however pass a JavaScript variable through a post or get though, and use that in your PHP. Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454342 Share on other sites More sharing options...
Lamez Posted February 1, 2008 Author Share Posted February 1, 2008 so I cannot do this? team[1]="<?php $row['1'] ?>"; rec[1]="(30-3)"; Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454873 Share on other sites More sharing options...
kenrbnsn Posted February 1, 2008 Share Posted February 1, 2008 You can do team[1]="<?php echo $row['1']; ?>"; rec[1]="(30-3)"; You were missing the "echo". Ken Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454875 Share on other sites More sharing options...
Lamez Posted February 1, 2008 Author Share Posted February 1, 2008 thanks the scripts are working great now thanks Link to comment https://forums.phpfreaks.com/topic/88718-solved-php-and-js/#findComment-454887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.