Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Easyer Way to do a Array?
Old 07-06-2009, 03:39 PM Easyer Way to do a Array?
Super Talker

Posts: 102
Trades: 0
My code
PHP Code:
<?
$i 
0;
$query mysql_query("SELECT * FROM news");
while(
$row mysql_fetch_array($query)){
    
$i++;
}
?>
var numofoptions =<? if($i == 0){ $i 0; } else { $i $i+1; } echo $i?>;
var testArr = new Array(numofoptions);
testArr[0] = document.getElementById("teletext_inner").innerHTML;
<?
$query1 
mysql_query("SELECT * FROM news");
while(
$row1 mysql_fetch_array($query1)){
    echo 
'testArr['.$row1['id'].'] = "'.$row1['content'].'";';
}
?>
setTimeout("changetele(0)",waittime);
// Comment
is there any easier way to do this?
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-06-2009, 05:43 PM Re: Easyer Way to do a Array?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try this:

PHP Code:
<?php
$query1 
mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM news");
$output_config true;
while(
$row1 mysql_fetch_array($query1)){
  if (
$output_config) {
    
$output_config false;
    
$num_rows_result mysql_fetch_array(@mysql_query($link,"Select FOUND_ROWS() AS total_rows"));
    
?>
var numofoptions =<? if($num_rows_result['total_rows'] == 0){ $num_rows_result['total_rows'] = 0; } else { $num_rows_result['total_rows'] = $num_rows_result['total_rows']+1; } echo $num_rows_result['total_rows']; ?>;
var testArr = new Array(numofoptions);
testArr[0] = document.getElementById("teletext_inner").innerHTML;
    <?php
  
}
  echo 
'testArr['.$row1['id'].'] = "'.str_replace('"','\"',$row1['content']).'";';
}
?>
I didn't run this, but the idea should be enough. The change to $row1['content'] is to escape double-quotes.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-06-2009, 05:51 PM Re: Easyer Way to do a Array?
Super Talker

Posts: 102
Trades: 0
is there anyway to get it so I don't have to use the ID as the array #?
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 07-06-2009, 05:56 PM Re: Easyer Way to do a Array?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Sure. This is javascript arrays. This demonstrates the method:

HTML Code:
<script type="text/javascript">
var testArr = [];
testArr.push("My First Value");
testArr.push("My Second Value");

for (var i=0; i< testArr.length; i++) {
  document.write("<p>" + testArr[i] + "</p>");
}
</script>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-06-2009, 06:33 PM Re: Easyer Way to do a Array?
Super Talker

Posts: 102
Trades: 0
So can you explain a little more on how I would use it with the JS that I am using already?
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 07-07-2009, 09:37 PM Re: Easyer Way to do a Array?
Super Talker

Posts: 102
Trades: 0
bump.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Easyer Way to do a Array?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23425 seconds with 12 queries