Variable question
Moderator: General Moderators
Variable question
Hi,
I have a txt file that i read into a variable, call it $data for now. When i echo the variable it echo's like this:
1
2
3
4
5
6
7
8
Which is what i would expect, my question is can i re-direct say half of the results? Instead of displaying 1-8 down the page can i display the results like this?
1 5
2 6
3 7
4 8
Any help please?
Thanks,
Slash.
I have a txt file that i read into a variable, call it $data for now. When i echo the variable it echo's like this:
1
2
3
4
5
6
7
8
Which is what i would expect, my question is can i re-direct say half of the results? Instead of displaying 1-8 down the page can i display the results like this?
1 5
2 6
3 7
4 8
Any help please?
Thanks,
Slash.
-
Netfeed
- Forum Newbie
- Posts: 1
- Joined: Wed Dec 15, 2004 8:05 am
- Location: Upon a hill where the grass is green
- Contact:
this isnt really that thought thrue from my side but why not:
save the data in a array
get the number of items of the array and then split them in two
echo array[0] and array[number_of_items/2]
echo array[1] and array[number_of_items/2+1]
echo array[2] and array[number_of_items/2+2]
and so on for until n == number_of_items/2
wouldnt that do?
edit: yay, my first post
save the data in a array
get the number of items of the array and then split them in two
echo array[0] and array[number_of_items/2]
echo array[1] and array[number_of_items/2+1]
echo array[2] and array[number_of_items/2+2]
and so on for until n == number_of_items/2
wouldnt that do?
edit: yay, my first post
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Code: Select all
<style>
span{
width:90px; background-color:#00FF00; margin-bottom:2px;
}
div{
background-color:#000000; border:2px solid #000000; color:red; width:100px;
}
</style>
<pre>
<?php
displayInHalf(35);
displayInHalf(20);
function displayInHalf($maxCount){
//echo $maxCount/2;
//echo "<div>";
for ($i = 1; $i <= $maxCount; $i++){
if ($i <= (ceil($maxCount/2))){
if ($i == 1){
echo "<div style = 'float:left;'><span>$i</span><br />";
}else{
echo "<span>$i</span><br />";
}
}else{
if ($i == ceil($maxCount/2) + 1){
echo "</div><div><span>$i</span><br />";
}elseif ($i == $maxCount){
echo "<span>$i</span><br /></div>";
}
else{
echo "<span>$i</span><br />";
}
}
}
//echo "</div>";
}
?>
</pre>
Last edited by raghavan20 on Fri Feb 03, 2006 1:12 pm, edited 3 times in total.
Here is another example:
Should output something like this:
Code: Select all
//untested
$array_cnt = count( $a_ );
//1/2 mark
$half = $array_cnt / 2;
echo '<div style="float: left;">';
for( $i=0; $i<$array_cnt; $i++ ){
if( $i == $half )
echo '</div><div>';
echo $a_[$i] . '<br />';
}
echo '</div>';Code: Select all
<div style="float: left;">1<br />
2<br />
3<br />
4<br />
</div><div>5<br />
6<br />
7<br />
8<br />
</div>hawleyjr | Please use
When i put $row[2] into the array:
All that it echo's is the last result in the array and not the whole list.
Is ther a way i can get $row[2] to keep all its data??
Thanks in advance
Slash.
hawleyjr | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi,
I have done as hawleyjr stated, and in a test in its simplest form it works, nice1. I thort from that i would beable 2 have a little play and get it to work the actual way i want. What i'm doing is pulling the data from mysql using mysql_fetch array. Like this:Code: Select all
$result = mysql_query("SELECT * FROM images where image_id = '2'");
$row = mysql_fetch_array($result);
echo "<IMG BORDER=\"0\" SRC=\"$row[2]\"><br>";Code: Select all
$a_ = array($row[2]);Is ther a way i can get $row[2] to keep all its data??
Thanks in advance
Slash.
hawleyjr | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
feyd | Please use
any one got a idea how i can echo it like this:
Insted of:
Thanks again for any help,
Slash.
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Ok,
So i've been trying to solve this on and off for a couple of days now. Any more help or suggestions.
I'm trying to echo out a <a href> that contains the link and the image that i want, which works. But i cant figure out for the life of me how to split the results, i've tried some great help from above but i dont think i can use <div> inside <a href>Code: Select all
<?
$result = mysql_query("SELECT * FROM test where album_id = '2'");
$result2 = mysql_query("SELECT * FROM images where album_id = '2'");
while($row = mysql_fetch_array($result)) {
echo "<a href=\"$row[3]$row[1]\n\">";
while($row2 = mysql_fetch_array($result2)) {
echo"<IMG BORDER=\"0\" SRC=\"$row2[2]\"><br>";
echo "</a>";
?>any one got a idea how i can echo it like this:
Code: Select all
Link1 <image1> Link4 <image4>
Link2 <image2> Link5 <image5>
Link3 <image3> Link6 <image6>Code: Select all
Link1 <image1>
Link2 <image2>
Link3 <image3>
Link4 <image4>
Link5 <image5>
Link6 <image6>Slash.
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]